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 several name-based virtual hosts on my Apache server. As I understand it, if the IP/port is matched, but the client supplies a blank or unknown host name, the first virtual host will be used. That does seem to be happening, but if I shuffle around the order, some virtual hosts will correctly display when accessed at, for instance, localhost, but two of them appear to return a redirect. The config files for one that works and one that don't work look exactly the same:

<VirtualHost *:80>
    #This is a simple site consisting of static pages.
    ServerName www.static.com
    ServerAlias static.com *.static.com
    DocumentRoot /var/www/static
</VirtualHost>

<VirtualHost *:80>
    #This is a WordPress site.
    ServerName www.wordpress.com
    ServerAlias wordpress.com *.wordpres.com
    DocumentRoot /var/www/wordpress
</VirtualHost>

(Actual URLs removed.) Putting the static site first and accessing localhost gets this in the logs:

www.static.com:80 127.0.0.1 - - [09/Aug/2012:23:33:58 -0400] "GET / HTTP/1.0" 200 1676 "-" "Lynx/2.8.8dev.5 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.8.6" "Host: localhost"

And it works fine. (It also works just fine with another static site I have.) Doing the same with the WordPress site gets this:

www.wordpress.com:80 127.0.0.1 - - [09/Aug/2012:23:32:50 -0400] "GET / HTTP/1.0" 301 379 "-" "Lynx/2.8.8dev.5 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.8.6" "Host: localhost"

Lynx tries localhost, then gets a 301, and then tries http://www.localhost/ (which doesn't work, obviously). The same things happens with 127.0.0.1, the server's local IP address, or a random name set in my hosts file to point to the server.

Also, I don't think it's just a Wordpress thing, because the exact same thing happens with a Django site I also have.

Thanks in advance for any ideas.

share|improve this question
    
Are the applications (Wordpress and the Django app) configured with localhost as the name? If Apache's not configured to redirect (and yours isn't, at least as not from the configs you've provided), then it's always the web apps. –  Shane Madden Aug 10 '12 at 4:12
    
Both use .htaccess files to handle access and redirects, among other things. Try renaming the files and see if they still redirect. I'm pretty sure it's just the .htaccess files that are causing that. –  nojak Aug 10 '12 at 4:47
    
@ShaneMadden: . . .In retrospect, I suppose that should have been fairly obvious. I can't speak to the WordPress site, because I didn't make it and I don't know WordPress, but I just started up the Django site with its built-in server on a different port and the same redirect happens. I'm still not sure why (the actual URL/name isn't specified anywhere in it, that I can remember or find), but thanks for helping me narrow it down. –  Charles Aug 10 '12 at 4:49
    
@nojak: Having tried it outside of Apache now, I doubt that's it, but thanks. –  Charles Aug 10 '12 at 4:50
    
Hmm. What's the content of the Location header that's in the 301 response? A base, empty Django setup shouldn't be redirecting - so that definitely might put a well-hidden bit of Apache config back on the table. –  Shane Madden Aug 10 '12 at 4:53

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.