Apache2.2虚拟主机设置
2007-12-16 00:39
471 查看
1.conf/httpd.conf文件尾添加
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#开启vhost模块
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
LoadModule vhost_alias_module modules/mod_vhost_alias.so
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
# 从"Host:"头中取得主机名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
UseCanonicalName Off
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
# 这种日志格式可以从第一个字段中提取出主机名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
LogFormat "%V %h %l %u %t "%r" %s %b" vcommon
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CustomLog E:/www/logs/access.log vcommon
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
# 在返回请求的文件名路径中包含主机名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
VirtualDocumentRoot E:/www/hosts/%0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#VirtualScriptAlias /www/hosts/%0/cgi-bin
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<VirtualHost *:80>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#这个一定要设置,否则服务器返回404(拒绝访问)。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<Directory "E:/www/hosts">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Order allow,deny
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Allow from all
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</Directory>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</VirtualHost>
2.修改 C:/WINDOWS/system32/drivers/etc/hosts增加映射
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
127.0.0.1 localhost
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
127.0.0.1 www.myext.com
3.E:/www目录设置(web服务文件):
E:/www>dir /w /s /b
------------------------------------------------------------------------------------------------------------------------------------
E:/www/hosts
E:/www/logs
E:/www/hosts/localhost
E:/www/hosts/www.myext.com
E:/www/hosts/localhost/index.html
E:/www/hosts/www.myext.com/index.html
------------------------------------------------------------------------------------------------------------------------------------
5.测试效果
启动apache,分别访问localhost/www.myext.com,则可以看到页面和访问日志:
www.myext.com 127.0.0.1 - - [16/Dec/2007:00:25:03 +0800] "GET / HTTP/1.1" 304 -
www.myext.com 127.0.0.1 - - [16/Dec/2007:00:25:38 +0800] "GET /index.html HTTP/1.1" 200 19
localhost 127.0.0.1 - - [16/Dec/2007:00:26:05 +0800] "GET / HTTP/1.1" 304 -
6.虚拟主机配置建议
虚拟主机少:用VirtualHost功能
改良:使用
虚拟主机多:使用代理吞吐(Proxy Throughput)功能(flag
不建议使用Tomcat的<Context…/>级+Apache的URL重写功能来“仿冒”Host,这样会对具体web应用的路径使用带来限制。
Apache动态VirtualHost (端口1)àTomcat<Host>级配置(ajp端口1)
Apache动态VirtualHost (端口2)àTomcat<Host>级配置(ajp端口2)
Apache动态VirtualHost (端口X)àTomcat<Host>级配置(ajp端口X)
注:Apache2.2中不再使用jk,而使用下列模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule status_module modules/mod_status.so
LoadModule proxy_http_module modules/mod_proxy_http.so
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#开启vhost模块
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
LoadModule vhost_alias_module modules/mod_vhost_alias.so
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
# 从"Host:"头中取得主机名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
UseCanonicalName Off
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
# 这种日志格式可以从第一个字段中提取出主机名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
LogFormat "%V %h %l %u %t "%r" %s %b" vcommon
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
CustomLog E:/www/logs/access.log vcommon
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
# 在返回请求的文件名路径中包含主机名
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
VirtualDocumentRoot E:/www/hosts/%0
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#VirtualScriptAlias /www/hosts/%0/cgi-bin
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<VirtualHost *:80>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#这个一定要设置,否则服务器返回404(拒绝访问)。
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<Directory "E:/www/hosts">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Order allow,deny
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
Allow from all
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</Directory>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</VirtualHost>
2.修改 C:/WINDOWS/system32/drivers/etc/hosts增加映射
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
127.0.0.1 localhost
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
127.0.0.1 www.myext.com
3.E:/www目录设置(web服务文件):
E:/www>dir /w /s /b
------------------------------------------------------------------------------------------------------------------------------------
E:/www/hosts
E:/www/logs
E:/www/hosts/localhost
E:/www/hosts/www.myext.com
E:/www/hosts/localhost/index.html
E:/www/hosts/www.myext.com/index.html
------------------------------------------------------------------------------------------------------------------------------------
5.测试效果
启动apache,分别访问localhost/www.myext.com,则可以看到页面和访问日志:
www.myext.com 127.0.0.1 - - [16/Dec/2007:00:25:03 +0800] "GET / HTTP/1.1" 304 -
www.myext.com 127.0.0.1 - - [16/Dec/2007:00:25:38 +0800] "GET /index.html HTTP/1.1" 200 19
localhost 127.0.0.1 - - [16/Dec/2007:00:26:05 +0800] "GET / HTTP/1.1" 304 -
6.虚拟主机配置建议
虚拟主机少:用VirtualHost功能
改良:使用
mod_vhost_alias
模块配置动态虚拟主机,这样新增主机就不需要重启Apache。
虚拟主机多:使用代理吞吐(Proxy Throughput)功能(flag
[P]),非单纯的URL重写,要加上端口转换,这样就可以使用多个Tomcat(防止相互影响)。
不建议使用Tomcat的<Context…/>级+Apache的URL重写功能来“仿冒”Host,这样会对具体web应用的路径使用带来限制。
Apache动态VirtualHost (端口1)àTomcat<Host>级配置(ajp端口1)
Apache动态VirtualHost (端口2)àTomcat<Host>级配置(ajp端口2)
Apache动态VirtualHost (端口X)àTomcat<Host>级配置(ajp端口X)
注:Apache2.2中不再使用jk,而使用下列模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule status_module modules/mod_status.so
LoadModule proxy_http_module modules/mod_proxy_http.so
相关文章推荐
- Apache2.2 虚拟主机设置
- apache 2.2设置单IP多端口的虚拟主机
- apache 2.2设置单IP多端口的虚拟主机
- django 项目部署在 Apache 后, 设置二级域名(Apache虚拟主机 、 万网二级域名设置)
- apache虚拟主机中设置泛域名解析的方法
- Apache下设置虚拟主机之基于域名的虚拟主机
- apache 虚拟主机设置
- 设置Apache虚拟主机的办法
- apache 服务器设置虚拟主机
- apache虚拟主机设置(单IP多域名)
- Apache虚拟主机和目录的设置
- Apache建立IP-Based和Name-based虚拟主机--httpd-vhosts.conf的设置
- apache 设置虚拟主机
- apache 虚拟主机设置
- apache虚拟目录和虚拟主机的设置
- ubuntu14.04系统下在apache2.4服务器上设置虚拟主机
- apache设置多个虚拟主机使多个域名可行有两种办法:1.多个IP解析到不同虚拟主机 2.单个IP绑定多个域名分解
- APACHE环境下同IP多域名虚拟主机的设置方案全攻略[ubuntu 12, linux]
- 在Apache中利用ServerAlias设置虚拟主机接收多个域名和设置域名泛解析
- 为什么apache要设置虚拟主机