I have configured Apache virtual host to run at port 8000 and in front of Apache I have Varnish on port 80. The problem is if I paste this in my browser:
example.com/a_directory
I am redirected to example.com:8000/a_directory
I get an unable to connect error. In the config file I have this:
<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>
This is almost certainly due to self-referential redirects, for example when a trailing slash is missing from a directory request. In such cases, in the absence of a ServerName directive, Apache will use the port that the request came in on - in your case, 8000. In Apache 2.x the ServerName directive supports a port specifier which is used to build redirects. From the Apache docs:
In your vhost block add something like (obviously change to your environment) ServerName www.foo.com:80, which should tell Apache to build those redirects using the upstream proxy port as opposed to the port it's listening on.
See http://httpd.apache.org/docs/2.2/mod/core.html for more information on this directive.