作者:DSSDD | 来源:互联网 | 2014-05-23 14:01
虚拟主机不要放在一个共同的端口,否则默认情况下只进入每一个虚拟主机目录。ServerRoot"/var/lib/apache2.2"DocumentRoot"/var/lib/apache2.2/htdocs"ErrorLog"logs/error_log"#
虚拟主机不要放在一个共同的端口,否则默认情况下只进入每一个虚拟主机目录。
ServerRoot "/var/lib/apache2.2"
DocumentRoot "/var/lib/apache2.2/htdocs"
ErrorLog "logs/error_log"
# apache 解析 .php 文件
SetHandler application/x-httpd-php
# myproject.com
Listen 192.168.55.9:80
DocumentRoot /var/lib/apache2.2/htdocs/myproject
ServerName myproject.com
# ScriptAlias /cgi-bin/ "/var/lib/apache2.2/htdocs/myproject/cgi-bin/"
# myproject1.com
Listen 192.168.55.9:81
DocumentRoot /var/lib/apache2.2/htdocs/myproject1
ServerName myproject1.com
# ScriptAlias /cgi-bin/ "/var/lib/apache2.2/htdocs/myproject1/cgi-bin/"
而我们在客户端的hosts文件里面也需要做IP映射,即:
192.168.55.9 myproject.com
192.168.55.9 myproject1.com
但是我们不需要在服务器端的hosts里面做IP映射。
实际上我们做请求时,还是用80端口来响应。
经测试,上面这种做法存在一个问题:即使是通过 myproject1.com 来访问,进入的还是 myproject.com 。
改为下面的可正常跳转:
ServerRoot "/var/lib/apache2.2"
DocumentRoot "/var/lib/apache2.2/htdocs"
ErrorLog "logs/error_log"
SetHandler application/x-httpd-php
NameVirtualHost *:80
Listen 192.168.55.9:80
# myproject.com
DocumentRoot /var/lib/apache2.2/htdocs/myproject
ServerName myproject.com
# ScriptAlias /cgi-bin/ "/var/lib/apache2.2/htdocs/myproject/cgi-bin/"
# myproject1.com
DocumentRoot /var/lib/apache2.2/htdocs/myproject1
ServerName myproject1.com
# ScriptAlias /cgi-bin/ "/var/lib/apache2.2/htdocs/myproject1/cgi-bin/"