Apache VirtualHost配置
2015-08-20 09:23
567 查看
转载:http://www.cnblogs.com/wpjsolo/archive/2012/01/19/2327457.html
以lampp环境为例子,其他环境只是配置文件的路径不同。 先要在 lampp/etc/httpd.conf ( 这个是Apache 总的配置文件)中,将虚拟路径的注释去掉。 #Include etc/extra/httpd-vhosts.conf 使httpd-vhosts.conf文件起作用,或者直接在httpd.conf中写配置也可以,但不建议这么做。 相关的配置有:Listen NameVirtualHost <VirtualHost> 1. Listen 要监听的端口,多个端口,要写多个Listen;否则Apache启动的时候,不会启动相应的套接字。 比如 Listen 80 Listen 8080 2.NameVirtualHost 如果没有这个,<VirtualHost>标签就没什么作用。 (感谢okiwill的指正,这里特指基于域名访问的情况,若是基于IP访问的,以第一个指定IP的VirtualHost为准,每个IP可以单独指定) 一个NameVirtualHost 可以对用多个<VirtualHost>,每个<VirtualHost>必须有自己的NameVirtualHost(我猜的) NameVirutalHost *:80 制定这个主机的IP和端口,如果服务器上有多个IP,就可以制定某个IP的某个端口是哪个 主机。 (新版的Apache已经去除了NameVirtualHost 这个配置,因为确实没什么用,参数在VirtualHost中都已经指明了) 3 最关键的VirtualHost 重要:Apache 在接受到请求时,首先会默认第一个VirtualHost,然后再找匹配的,如果没有匹配的,就是第一个VirtualHost起作用。 因此在httpd.conf中,将<Dicrectory />(这个是所有目录的默认配置) 和 <Direcotry /opt/lampp/htdocs>的权限,都是deny from all.作为默认。 所以,我的第一个VirtualHost是 <VirtualHost *:80> ServerName * DocumentRoot </opt/lampp/htdocs/guest> <Directory /opt/lampp/htdocs/guest> Order deny,allow Allow from all </Direcotry> <VirtualHost/> 后面的,依次添加就可以 <VirtualHost *:80> ServerName www.myweb1.com DocumentRoot </opt/lampp/htdocs/myweb1> <Directory /opt/lampp/htdocs/myweb1> Order deny,allow Allow from all </Direcotry> <VirtualHost/> “2.NameVirtualHost 如果没有这个,<VirtualHost>标签就没什么作用。”这句话似乎有待考究?
根据Apache官方的说法,To use name-based virtual hosting, you must designate the IP address (and possibly port) on the server that will be accepting requests for the hosts. This is configured using the NameVirtualHost directive.
也就是说,NameVirtualHost这个Directive是用于Name-based Virtual Hosts的情形,没有的话就是IP-based Virtual Hosts,这时候不能说“<VirtualHost>标签没什么用”吧?
请博主斟酌。
http://httpd.apache.org/docs/2.2/en/vhosts/name-based.html @okiwill
谢谢指正,当时确实没有考虑这种情况。
应该说NameVirtualHost这个标签是可以省略的。
在没有NameVirtualHost的时候,后续VirtualHost中ServerName就失效了。会以第一个VirtualHost的DocumentRoot以及其他相关属性为准,基于IP的。
相关文章推荐
- java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor vers
- 在mac中配置apache+php5.3+mysql的环境,修改hosts
- Apache 隐藏入口文件以及防盗链.htaccess 文件
- apache wicket 7.X让html回归webapp目录下
- Apache JMeter--网站自动测试与性能测评
- 如何配置Mac系统自带的ApacheWeb服务器 测试10.10可用
- Mac 中安装 Apache Ant
- 开发笔记-Linux-Apache-PHP-CI
- Apache Ambari
- RM源码之org.apache.hadoop.service.AbstractService分析
- wamp中的Apache开启gzip压缩提高网站的响应速度
- How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS
- linux下 Apache 配置虚拟主机三种方式
- Apache虚拟主机配置
- windows server 已经编译过的apache 源码
- Apache Ant 实例介绍,以及部分标签介绍
- 1.7-Apache用户认证
- Apache服务器CPU利用率、Load值及Running值高导致WEB无法访问
- 安装Apache的时候80端口被PID为4的系统进程所占用
- Linux命令安装Apache