上次安装httpd2.4对应的配置文件:/usr/local/apache2.4/conf/httpd.conf
编辑配置文件,修改如下4个地方
ServerName
Require all denied
AddType application/x-httpd-php .php
DirectoryIndex index.html index.phpphp
[root@test-a ~]# /usr/local/apache2.4/bin/apachectl start httpd (pid 6328) already running
# Windows终端: telnet 192.168.77.134 80 正在链接192.168.77.134...没法打开到主机的链接。 在端口 80: 链接失败 [root@test-a ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT # 再次telnet能够访问了
# 改完配置须要从新加载配置,加载前最好检测配置是否正确 [root@test-a ~]# /usr/local/apache2.4/bin/apachectl -t Syntax OK # 加载配置 [root@test-a ~]# /usr/local/apache2.4/bin/apachectl graceful
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
vim /usr/local/apache2/conf/httpd.conf # 搜索httpd-vhost,去掉#,使支持虚拟主机 vim /usr/local/apache2/conf/extra/httpd-vhosts.conf # 改成以下 <VirtualHost *:80> ServerAdmin test@163.com # 管理员邮箱,能够不用配置 DocumentRoot "/tmp/web-default" # 网站资源目录 ServerName test.com # 域名 ServerAlias www.test.com # 域名别名 ErrorLog "logs/test.com-error_log" # 错误日志 CustomLog "logs/test.com-access_log" common # 访问日志 </VirtualHost> <VirtualHost *:80> DocumentRoot "/tmp/web-1/" ServerName www.123.com </VirtualHost> [root@test-a apache2.4]# bin/apachectl -t Syntax OK [root@test-a apache2.4]# bin/apachectl graceful
编写测试文件1.php放到/tmp/web-default目录下,2.php放到/tmp/web-1/下, 访问测试html
[root@test-a apache2.4]# curl -x 192.168.77.134:80 test.com 1.php [root@test-a apache2.4]# curl -x 192.168.77.134:80 www.test.com 1.php [root@test-a apache2.4]# curl -x 192.168.77.134:80 www.123.com 2.php [root@test-a apache2.4]# curl -x 192.168.77.134:80 www.example.com # 访问默认虚拟主机 1.php