我按照说明这里使用内置的Web服务器运行Django,并且可以使用 python manage.py runserver 成功运行它。如果我从网络服务器本地访问127.0.0.1:port,我得到的Django页面指示它的工作。
我意识到Django网络服务器不是一个生产服务器,但它是对我来说重要的是测试目的,以便能够从外部世界访问它 - 即不是来自服务器上的Web浏览器,而是来自不同的计算机。
我尝试过:
http:// mywebserver:port_django_runs_on但它没有工作。我也尝试使用IP(基于ifconfig)来访问:
http:// myipaddress:port_django_runs_on哪些不起作用。
Web服务器是运行,所以它必须从外面访问,我只是不知道如何。我正在使用Apache运行Linux,尽管我还没有配置Django与Apache。
有关如何做到这一点的任何想法?
解决方案您必须运行开发服务器,使其侦听界面到您的网络。
例如
python manage.py runserver 0.0.0.0:8000侦听端口8000上的每个界面。
无论您是使用IP还是主机名访问Web服务器。我想你还在自己的局域网中。 如果你真的想从外部访问服务器,你还必须配置你的路由器转发端口,例如
检查您的服务器上的防火墙是否允许与使用端口的传入连接!
假设您可以从外部成功访问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:
mywebserver:port_django_runs_onbut it did not work. I also tried using the IP instead (based on ifconfig) to access:
myipaddress:port_django_runs_onwhich 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:8000listens 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网络服务器
发布评论