在CentOS 6.3中安装Apache WebServer

时间:2020-03-21 11:45:17  来源:igfitidea点击:

在此教程中,将介绍如何安装Apache并使用Apache托管一个简单的网站。

环境

我的测试方案设置如下

WebServer详细信息:

Operating System  :  CentOS 6.3 32bit server
Hostname          :  web.theitroad.com
IP Address        :  192.168.1.250

客户端详细信息:

Operating System  :  CentOS 6.3 32bit Desktop
Hostname          :  client.theitroad.com
IP Address        :  192.168.1.251

我已经在我的设置中有一个DNS服务器,我已将DNS服务器正常配置为服务器和客户端详细信息。

服务器端配置

准备工作:

1.设置Web服务器的主机名

[Hyman@theitroad ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=web.theitroad.com

2.在"etc/hosts"文件中添加WebServer主机名

[Hyman@theitroad ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250   web.theitroad.com
192.168.1.250   theitroad.com

3.安装apache.

检查并删除任何先前安装的包

[Hyman@theitroad ~]# rpm -qa | grep httpd

或者

[Hyman@theitroad ~]# yum list installed | grep httpd

现在安装'httpd'包

[Hyman@theitroad ~]# yum install httpd* -y

4.配置Apache.

[Hyman@theitroad ~]# vi /etc/httpd/conf/httpd.conf 
## line no 262 - Set the server admin mail id which is used to receive mail generated by apache ##
ServerAdmin Hyman@theitroad
## line no 276 - Set the website name ##
ServerName theitroad.com:80
## line no 292 - Set the web pages folder ##
DocumentRoot "/var/www/html"
## line no 402 - Sent the index or home page of the website ##
DirectoryIndex theitroad.html

5.创建示例索引或者主页

在'/var/www/html /'目录中创建索引或者主页HTML文件

[Hyman@theitroad ~]# vi /var/www/html/theitroad.html 
<html>
<body bgcolor=blue>
        <h1> Welcome to theitroad Website </h1> 
</body>
</html>

6.允许WebServer通过防火墙

[Hyman@theitroad ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

重新启动iptables以保存更改

[Hyman@theitroad ~]# service iptables restart
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:                         [  OK  ]

7.启动Apache Web服务器

[Hyman@theitroad ~]# service httpd start
Starting httpd:                                            [  OK  ]
[Hyman@theitroad ~]# chkconfig httpd on

客户端配置

1.在"/etc/hosts"文件中添加Web服务器和客户端IP地址和主机名

[Hyman@theitroad ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.251   client.theitroad.com
192.168.1.250   theitroad.com

2.检查Apache WebServer

在客户端中打开Firefox并在地址列中键入https://theitroad.com。