我在一台服务器上托pipe两个网站。 每个都有自己的VirtualHost定义。 第一个网站很好地工作,但当我尝试访问第二个我redirect到第一个。 这就像Apache不能识别ServerName的正确的VirtualHost,并将我redirect到默认(第一)网站。
有没有日志或什么东西,我可以看到Apache处理我的请求时采取了哪些步骤? 当它试图find一个匹配的VirtualHost时,是否在任何地方logging了它所使用的ServerName?
更新:
我为我的第二个网站的子域添加了一个VirtualHost部分,并且工作正常。 当我在浏览器中input“interface.domain.com”时,它会从正确的运行在8501端口的应用程序服务器中呈现页面。 但是,当我尝试“www.domain.com”redirect到我的第一个网站。
以下是我的第二个站点的虚拟主机文件。
<VirtualHost *:80> ServerName www.domain.com DocumentRoot /home/domain/current/public RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ http://localhost:8501/$1 [P] </VirtualHost> <VirtualHost *:80> ServerName interface.domain.com DocumentRoot /home/domain/current/public RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ http://localhost:8501/$1 [P] </VirtualHost>
apache2ctl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 1.2.3.4. Set the 'ServerName' directive globally to suppress this message VirtualHost configuration: 1.2.3.4:443 www.domainfirst.com (/etc/apache2/sites-enabled/https_www_domainfirst_com.conf:1) 1.2.3.4:80 is a NameVirtualHost default server domainfirst.com (/etc/apache2/sites-enabled/domainfirst_com.conf:1) port 80 namevhost domainfirst.com (/etc/apache2/sites-enabled/domainfirst_com.conf:1) port 80 namevhost www.domainfirst.com (/etc/apache2/sites-enabled/www_domainfirst_com.conf:1) *:80 is a NameVirtualHost default server domain.com (/etc/apache2/sites-enabled/domain_com.conf:1) port 80 namevhost domain.com (/etc/apache2/sites-enabled/domain_com.conf:1) port 80 namevhost www.domain.com (/etc/apache2/sites-enabled/www_domain_com.conf:1) port 80 namevhost interface.domain.com (/etc/apache2/sites-enabled/www_domain_com.conf:10) ServerRoot: "/etc/apache2" Main DocumentRoot: "/var/www/html" Main ErrorLog: "/var/log/apache2/error.log" Mutex watchdog-callback: using_defaults Mutex rewrite-map: using_defaults Mutex ssl-stapling: using_defaults Mutex proxy: using_defaults Mutex ssl-cache: using_defaults Mutex default: dir="/var/lock/apache2" mechanism=fcntl PidFile: "/var/run/apache2/apache2.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="www-data" id=33 Group: name="www-data" id=33
解:
清除浏览器caching。 我的浏览器已经caching了一个规则来转发请求到其他网站。
除非你是一个非常有经验的Apachepipe理员,并且确切地知道你在做什么,否则不要在你的<VirtualHost>标记中混合使用IP:port和*:port定义。
任何parsing为1.2.3.4域名(在你的例子中)将被你的一个绑定到1.2.3.4:80的绑定服务,不pipe使用哪个主机名。
如果你的*:80虚拟主机中的服务器名称和服务器错误不能parsing为1.2.3.4,那么其他的东西是错误的。 如果他们确实解决了这个IP,只需将<VirtualHost 1.2.3.4:80>更改为<Virtualhost *:80>
补充说明:如果你的服务器上只有一个IP,只能使用*:port版本,这样可以避免混淆
更多评论:部分问题可能是您清理所有域名的方式。 这一定要一贯地做,否则我们的努力将是徒劳的。 apache决定发送请求的服务器的方式如下。 这只是简单的工作,在这个过程中的任何错误 ,甚至无法生存,即使是最基本的Apache版本的testing:
<VirtualHost>标记,那么该虚拟主机将接收到该请求 ServerName和ServerAlias指令,以查找与所连接的IP /端口匹配的任何<VirtualHost> ,并匹配请求附带的HTTP Host头。 apachectl -S的输出中的第一个<VirtualHost>将与接收请求的匹配。 apachectl -S输出中为特定ip / port组合输出的第一个虚拟主机。 记住IP可能只是* 。