简体   繁体   English

无法从本地服务器外部连接到Django

[英]Cannot Connect to Django from outside the Local Server

I built a basic Django project and app on Centos7, but I cannot access it externally. 我在Centos7上构建了一个基本的Django项目和应用程序,但无法从外部访问它。 Check the configuration below. 检查以下配置。

[root@pytoncentos7 myproject]# cat settings.py | grep ALLOWED
ALLOWED_HOSTS = ['*']

And I run my server as below. 然后按以下方式运行服务器。

[root@pytoncentos7 myproject]#  python3.6 manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
May 24, 2018 - 15:03:04
Django version 2.0.5, using settings 'myproject.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Also, the firewall is not running 另外,防火墙没有运行

[root@pytoncentos7 myproject]# firewall-cmd --state
not running

Below are the list of my ports. 以下是我的端口列表。

[root@pytoncentos7 myproject]# netstat -lptun
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       
PID/Program name
tcp        0      0 127.0.0.1:8000          0.0.0.0:*               LISTEN      
1643/python3.6
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      
876/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      
982/master
tcp6       0      0 :::3306                 :::*                    LISTEN      
986/mysqld
tcp6       0      0 :::22                   :::*                    LISTEN      
876/sshd
tcp6       0      0 ::1:25                  :::*                    LISTEN      
982/master
udp        0      0 127.0.0.1:323           0.0.0.0:*                           
636/chronyd
udp6       0      0 ::1:323                 :::*                                
636/chronyd

Also, when I try to connect from the outside to port 8000, it fails !!. 另外,当我尝试从外部连接到端口8000时,它将失败! But ofcourse I can telnet locally. 但是我当然可以在本地进行远程登录。 And at the same time, I have Apache running on 80 and reachable from internal/external, but when I disable Apache and run Django on port 80, I can still connect locally but not external 同时,我的Apache运行在80上,并且可以从内部/外部访问,但是当我禁用Apache并在端口80上运行Django时,我仍然可以在本地连接,但不能在外部连接

The Django server is just a VM running on my local computer Django服务器只是在我的本地计算机上运行的VM

From https://docs.djangoproject.com/en/2.0/ref/django-admin/#runserver https://docs.djangoproject.com/en/2.0/ref/django-admin/#runserver

Note that the default IP address, 127.0.0.1, is not accessible from other machines on your network. 请注意,无法从网络上的其他计算机访问默认IP地址127.0.0.1。 To make your development server viewable to other machines on the network, use its own IP address (eg 192.168.2.1) or 0.0.0.0 or :: (with IPv6 enabled). 为了使您的开发服务器对网络上的其他计算机可见,请使用其自己的IP地址(例如192.168.2.1)或0.0.0.0或::(启用IPv6)。

You must run with the command python3.6 manage.py runserver 0.0.0.0:8000 您必须使用命令python3.6 manage.py runserver 0.0.0.0:8000

Then figure out the VM's local IP and navigate to it 然后找出虚拟机的本地IP并导航到它

http://192.168.0.XXX:8000   <--- Use local IP of VM

runserver without specifying an IP will only listen to the loopback interface. 未指定IP的runserver将仅侦听回送接口。

You need python3.6 manage.py runserver 123.123.123.123 (assuming the IP of your network interface is "123.123.123.123"). 您需要python3.6 manage.py runserver 123.123.123.123 (假设您的网络接口的IP为“ 123.123.123.123”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使在同一网络上也无法从外部连接到Apache服务器 - Cannot connect to Apache server from outside even on the same network 无法将 Django 连接到 SQL 服务器 - Cannot connect Django to SQL server 将Django连接到本地网络上的远程mysql服务器 - Connect Django to remote mysql server on a local network 无法使用Django连接到本地Postgresql服务器 - Unable to connect to local Postgresql server using django docker中的ngrok无法连接到Django开发服务器 - ngrok in docker cannot connect to Django development server Django 无法连接到 SQL 服务器 2019 - Django Cannot Connect to SQL Server 2019 从非本地网络机器连接到python开发Django服务器 - Connect to python development django server from a non-local network machine 如何在我的本地笔记本电脑中使用来自 Django 应用程序的托管服务标识连接到 Azure SQL 服务器 - How to connect to Azure SQL Server using Managed Service Identity from Django application in my local laptop 无法从其他Windows计算机访问本地ubuntu服务器上的Django服务器 - Django server on local ubuntu server cannot be reached from another windows machine Django(容器化)无法连接到本地机器上的 MySQL(容器化) - Django (containerized) cannot connect to MySQL (containerized) on local machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM