views:

269

answers:

2

I followed the instructions here to run Django using the built-in webserver and was able to successfully run it using "python manage.py runserver". If I access 127.0.0.1:port locally from the webserver, I get the Django page indicating it worked.

I realize the Django webserver is not a production server, but it's important for me for testing purposes to be able to access it from the outside world -- i.e. not from a webbrowser on the server, but from a different computer. How can I do this? I tried:

http://mywebserver:port_django_runs_on

but it did not work. I also tried using the IP instead (based on ifconfig) to access:

http://myipaddress:port_django_runs_on 

though that did not work either. Any ideas on how to do this? The web server is running so it must be accessible from the outside, I'm just not sure how. I am running Linux with Apache, though I have not configured django with apache. Thanks!

+7  A: 

You have to run the development server such that it listens on the interface to your network.

E.g.

python manage.py runserver 0.0.0.0:8000

listens on every interface on port 8000.

It doesn't matter whether you access the webserver with the IP or the hostname. I guess you are still in your own LAN.
If you really want to access the server from outside, you also have to configure your router to forward port e.g. 8000 to your server.

Update: Check your firewall on your server whether incoming connections to the port in use are allowed!

Assuming you can access your Apache server from the outside successfully, you can also try this:

  • Stop the Apache server, so that port 80 is free.
  • Start the development server with sudo python manage.py runserver 0.0.0.0:80
Felix Kling
Using "python manage.py runserver 0.0.0.0:8000" still gives the same result. Could you say more about how I can configure Apache to handle this port?
@user248237 : You run the development server, this is totally unrelated to the Apache web server. The development server is a standalone web server.
Felix Kling
It requires special privileges to use port 80. You can try a `sudo python manage.py runserver 80`.
S.Lott
@S.Lott: Oh thank you. I know, it was in my mind as wrote it but somehow didn't make it to the keyboard ;)
Felix Kling
+3  A: 

Pick one or more from:

  • Your application isn't successfully listening on the intended IP:PORT
    • Because you haven't configured it successfully
    • Because the user doesn't have permission to
  • Your application is listening successfully on the intended IP:PORT, but clients can't reach it because
    • The server local iptables prevents it.
    • A firewall prevents it.

So, you can check that your application is listening successfully by running lsof -i as root on the machine and look for a python entry with the corresponding port you've specified.

Non-root users generally cannot bind to ports < 1024.

You'll need to look at iptables -nvL to see if there's a rule that would prevent access to the ip:port that you are trying to bind your application to.

If there is an upstream firewall and you don't know much about it, you'll need to talk to your network administrators.

MattH