问题描述
我按照说明使用内置的Web服务器运行Django,并且可以使用
检查您的服务器上的防火墙是否允许与使用端口的传入连接!
假设您可以从外部成功访问Apache服务器,还可以尝试以下方式:
- 停止Apache服务器,以便端口 80 是免费的。
- 使用启动开发服务器sudo python manage.py runserver 0.0.0.0:80
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 web browser on the server, but from a different computer.
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
which did not work either.
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.
Any ideas on how to do this?
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.
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
这篇关于如何从外界访问本地的Django网络服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!