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 learning Django and wanted to test hosting it on an Ubuntu computer I have. I decided to serve it with Apache and mod_wsgi. I got most things working, but I have one thing puzzling me. I can access the website only from my external IP address, not from say 127.0.0.1 or my 192.168.x.x address.

My django.conf file in /etc/apache2/sites-available is

<VirtualHost *:80>

WSGIScriptAlias / /home/username/project

ServerName my_external_ip

Alias /media/ /home/username/project/media
Alias /static/ /home/username/project/static

<Directory /home/username/project>
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

If I set ServerName to 127.0.0.1 then the page only loads from there. Also I should add, it doesn't exactly "not load" when I access from other locations, it just shows an Apache page titled "Index of /" with no contents.

What is stopping Apache serving pages in all cases, and how can I make it serve pages as 127.0.0.1 etc..? Is there a better way I should host it?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Your answer lies in apache2ctl -S - the "default" site from the install takes precedence when the Host header that the HTTP client sends doesn't match a ServerName or ServerAlias in one of the other <VirtualHost> blocks on the port.

If you want your Django site to be handling all requests to the server, then disable the default:

a2dissite default

...then restart Apache.

Otherwise, if you want to be a little more nuanced about having Django take over, you can add a ServerAlias to the config of its <VirtualHost>:

ServerAlias internal.ip external.ip external.dns.name
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.