在CentOS 6.3中安装Apache Webserver

在本入门指南中,我将向您展示如何安装Apache并使用Apache托管示例网站。

情境

在本入门指南中,我的测试方案设置如下

网络服务器详细信息:

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

客户资料:

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

我的设置中已经有一个DNS服务器,并且已经使用服务器和客户端详细信息正确配置了DNS服务器。

服务器端配置

先决条件:

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

[[email protected] ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=web.ostechnix.com

2.在“ etc / hosts”文件中添加网络服务器主机名

[[email protected] ~]# 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.ostechnix.com
192.168.1.250   www.ostechnix.com

3.安装Apache
检查并删除任何以前安装的软件包

[[email protected] ~]# rpm -qa | grep httpd

要么

[[email protected] ~]# yum list installed | grep httpd

现在安装“ httpd”软件包

[[email protected] ~]# yum install httpd* -y

4.配置Apache

[[email protected] ~]# 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 [email protected]
## line no 276 - Set the website name ##
ServerName www.ostechnix.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 ostechnix.html

5.创建样本索引或主页
在“ / var / www / html /”目录中创建索引或主页html文件

[[email protected] ~]# vi /var/www/html/ostechnix.html 


        

Welcome to OSTECHNIX Website

 

6.允许Web服务器通过防火墙

[[email protected] ~]# 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以保存更改

[[email protected] ~]# 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服务器

[[email protected] ~]# service httpd start
Starting httpd:                                            [  OK  ]
[[email protected] ~]# chkconfig httpd on

客户端配置

1.在“ / etc / hosts”文件中添加网络服务器和客户端IP地址以及主机名

[[email protected] ~]# 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.ostechnix.com
192.168.1.250   www.ostechnix.com

2.检查Apache Web服务器

在客户端中打开Firefox,然后在地址栏中键入https://www.ostechnix.com。 ostechnix网站的索引页面即将打开。

而已。祝你有美好的一天!!!
 

Sidebar