Apache将redirect到每个目录的不同端口

我已经configuration了Apache虚拟主机在端口8000上运行,而在Apache之前我在端口80上有了Varnish。问题是如果我把它粘贴到我的浏览器中:

example.com/a_directory

我被redirect到example.com:8000/a_directory

我得到一个无法连接错误。 在configuration文件中我有这个:

<VirtualHost *:8000> ServerAdmin [email protected] DocumentRoot /var/www DirectoryIndex index.php index.html index.htm <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www> AllowOverride All </Directory> # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/access.log combined </VirtualHost> 

这几乎可以肯定是由于自引用redirect导致的,例如,当目录请求中没有尾部的斜线时。 在这种情况下,在没有ServerName指令的情况下,Apache将使用请求进来的端口 – 在您的情况下,8000.在Apache 2.x中,ServerName指令支持用于构buildredirect的端口说明符。 从Apache文档:

ServerName指令设置服务器用来标识自身的请求scheme,主机名和端口。 这在创buildredirectURL时使用。

在你的虚拟主机块中添加类似于(显然改变你的环境)ServerName http://www.foo.com:80,这应该告诉Apache使用上游代理端口而不是它正在监听的端口来build立这些redirect&#x3002;

有关此指令的更多信息,请参阅http://httpd.apache.org/docs/2.2/mod/core.html