问题
This is probably a very basic question. I SSH to my virtual Ubuntu server and start a django webserver running on localhost:
Downloading/unpacking django
Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Successfully installed django
Cleaning up...
Performing system checks...
System check identified no issues (0 silenced).
You have unapplied migrations; your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
April 13, 2016 - 14:16:19
Django version 1.9.5, using settings 'mysite.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
The Ubuntu server has a static IP [x.xxx.xxx.xxx] so from another machine on another network I try to access the above website in a browser using that static IP address:
x.xxx.xxx.xxx:8000
But I get:
This site can’t be reached
x.xxx.xxx.xxx refused to connect.
ERR_CONNECTION_REFUSED
So I assume that I cannot access the website like this and that is only available on the host it self even though the host has an external/static IP address?
Edit:
The answer is also in: https://docs.djangoproject.com/en/1.9/intro/tutorial01/#the-development-server
python manage.py runserver 0.0.0.0:8000
回答1:
You need to run your web server on 0.0.0.0:8000
, then externally you would use either ip or host name to access. Using 0.0.0.0
means the django service would listen to all configured network interfaces.
Check wikipedia on details about 0.0.0.0.
Another answer on serverfault could be helpful.
来源:https://stackoverflow.com/questions/36601409/accessing-localhost-externally