Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 xxx@xxx.org.au

    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>
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
add comment

1 Answer 1

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 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.

share|improve this answer
add comment

Your Answer

 
discard

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.