Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

I am redirected to

I get an unable to connect error. In the config file I have this:

<VirtualHost *:8000>

    DocumentRoot /var/www
    DirectoryIndex index.php index.html index.htm 

    <Directory />
        Options FollowSymLinks
        AllowOverride None

    <Directory /var/www>
        AllowOverride All

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

share|improve this question
What's running on Apache, I'm guessing PHP code from your DirectoryIndex settings? That's likely what's throwing the redirect. – Shane Madden Nov 28 '11 at 15:51

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:

The ServerName directive sets the request scheme, hostname and port that the server uses to identify itself. This is used when creating redirection URLs.

In your vhost block add something like (obviously change to your environment) ServerName, which should tell Apache to build those redirects using the upstream proxy port as opposed to the port it's listening on.

See for more information on this directive.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.