首先修改httpd.conf配置文件。
vim conf/httpd.conf
添加:
Listen 1234
然后把
改成
-
# Virtual hosts
-
Include conf/extra/httpd-vhosts.conf
就是使用虚拟配置,然后去编辑conf/extra/httpd-vhosts.conf,添加:
-
24 <VirtualHost *:1234>
-
25 DocumentRoot "/xxx/xxx/xxx"
-
26 ServerName localhost
-
33 <Directory "/xxx/xxx/xxx">
-
35 Require all granted
-
36 </Directory>
-
37 </VirtualHost>
然后重启apache:
apachectl restart
然后在浏览器访问就可以了,
这里要补充一句, 网上很多资料说conf/extra/httpd-vhosts.conf添加:
-
33 <Directory "/xxx/xxx/xxx">
-
35 Order allow,deny
-
36 Allow from all
-
37 </Directory>
这是2.2版本修改配置的方法,2.4版本换套路了,如果这么配置,log日志会报错:
client denied by server configuration: /xxx/xxx/xxx, referer: http://xxx/xxx/xxx
所以,对于2.4版本的apache,正确的配置方法是:
-
33 <Directory "/xxx/xxx/xxx">
-
35 Require all granted
-
36 </Directory>
本文详细介绍了如何在Apache 2.4中配置虚拟主机,包括修改httpd.conf文件,添加监听端口,配置虚拟主机路径,以及正确设置目录权限。特别指出,在2.4版本中,'Require all granted'替代了旧版的权限设置方法。
1484

被折叠的 条评论
为什么被折叠?



