Apache VirtualHost配置
以lampp环境为例子,其他环境只是配置文件的路径不同。先要在 lampp/etc/httpd.conf ( 这个是Apache 总的配置文件)中,将虚拟路径的注释去掉。
#Include etc/extra/httpd-vhosts.conf
使httpd-vhosts.conf文件起作用,或者直接在httpd.conf中写配置也可以,但不建议这么做。
相关的配置有:ListenNameVirtualHost
1.Listen要监听的端口,多个端口,要写多个Listen;否则Apache启动的时候,不会启动相应的套接字。
比如
Listen 80
Listen 8080
2.NameVirtualHost 如果没有这个,标签就没什么作用。
(感谢okiwill的指正,这里特指基于域名访问的情况,若是基于IP访问的,以第一个指定IP的VirtualHost为准,每个IP可以单独指定)
一个NameVirtualHost 可以对用多个,每个必须有自己的NameVirtualHost(我猜的)
NameVirutalHost *:80
制定这个主机的IP和端口,如果服务器上有多个IP,就可以制定某个IP的某个端口是哪个 主机。
(新版的Apache已经去除了NameVirtualHost 这个配置,因为确实没什么用,参数在VirtualHost中都已经指明了)
3最关键的VirtualHost
重要:Apache 在接受到请求时,首先会默认第一个VirtualHost,然后再找匹配的,如果没有匹配的,就是第一个VirtualHost起作用。
因此在httpd.conf中,将(这个是所有目录的默认配置)
和 的权限,都是deny from all.作为默认。
所以,我的第一个VirtualHost是
ServerName *
DocumentRoot
Order deny,allow
Allow from all
后面的,依次添加就可以
ServerName www.myweb1.com
DocumentRoot
Order deny,allow
Allow from all
页:
[1]