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 am trying to set up apache2 and django to support two different sites, example.com and beta.example.com, from the same server. But requests for beta.example.com are going to example.com.

My apache configuration file includes:

NameVirtualHost *:80

Include /var/www/main/sites-enabled
Include /var/www/beta/sites-enabled

For main/, sites-enabled holds one file, main, which is linked to sites/available/main. This includes:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /home/mycode/main
</VirtualHost>

<Location "/">
    [Django & Python stuff]
    SetEnv DJANGO_SETTINGS_MODULE main.settings
</Location>

For beta/, sites-enabled has one file, beta, with a similar symlink.

<VirtualHost *:80>
    ServerName beta.example.com
    DocumentRoot /home/mycode/beta
</VirtualHost>

<Location "/beta.example.com/">
    [Django & Python stuff]
    SetEnv DJANGO_SETTINGS_MODULE beta.settings
</Location>

I have set up my DNS so beta.example.com is forwarded to example.com (I think; I'm weak on DNS). I do think requests for beta.example.com are hitting the http server as such, as the access logs show requests for image files in connetion with beta.example.com (I've configured so Apache, not Django, handles image files).

But the page I get at beta.example.com is the page I'd expect for example.com. And when I start the server, I'm warned that "NameVirtualHost *:80 has no VirtualHosts."

What might I be doing wrong here?

UPDATE This seems to be a DNS problem. The changes suggested work as required for requests inside the LAN (where the router has assigned the hostname beta.example.com the local IP address of the server) but not for requests outside the LAN. Review of the other_vhosts_access.log shows that inside LAN requests for beta.example.com are appearing as beta.example.com, while outside requests are appearing as example.com.

I missed this last night because I looked at the server behavior from outside the LAN, and didn't check the inside requests. Sorry.

I'll go look at the DNS arrangements. Thanks for the help.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I am not sure this is precisely your problem but NameVirtualHost does not have a colon. Also, the "Location" for the beta site is incorrect. Put your Location tag in both cases inside the VirtualHost container and stick to "/" in both cases.

share|improve this answer
    
Thx. That colon was a typo in the post, it isn't present in the configuration file. I moved the close of the Virtual Host blocks to enclose the Location blocks, and changed the beta Location to "/", but this didn't fix the problem. –  chernevik Jun 25 '09 at 23:13
    
OK. Could you post some logs? But even before that - isolate the problem - so start by making sure the two virtual hosts actually work without django - just a simple static page. I suspect once you solve this bit the rest will go smoothly –  mfx Jun 26 '09 at 8:55
    
See above. Your edits seem to have worked, it's a DNS problem. –  chernevik Jun 26 '09 at 16:52
    
Having '<Location />' inside of 'VirtualHost' is redundant as that is the default context anyway. –  Graham Dumpleton Jun 27 '09 at 11:18

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.