简体   繁体   English

Localhost服务器拒绝连接

[英]Localhost Server Refusing Connection

I just set up Django on a dreamhost server. 我只是在dreamhost服务器上设置Django。 Ran through everything, but can't seem to get the welcome page. 通过一切,但似乎无法获得欢迎页面。 I got to the point where it says "Development server is running at 127.0.0.1:8002 (tried with 8000 but got the "that port is already in use error). 我说到“开发服务器运行在127.0.0.1:8002(尝试使用8000但是得到了”该端口已经在使用中的错误)。 When I try to access that address in my browser in Chrome I get Error 102 (net::ERR_CONNECTION_REFUSED): The server refused the connection. 当我尝试在Chrome浏览器中访问该地址时,我收到错误102(net :: ERR_CONNECTION_REFUSED):服务器拒绝连接。

Any idea why this is happening? 知道为什么会这样吗? I am stuck in a loop, I have no clue what is going on. 我陷入了困境,我不知道发生了什么。 Help is sincerely appreciated. 帮助是真诚的感谢。

You need to know your server's IP or domain address. 您需要知道服务器的IP或域地址。 If you used example.com to access you server SSH, then launching Django with 如果您使用example.com访问服务器SSH,则启动Django

./manage.py runserver 0.0.0.0:8002 ./manage.py runserver 0.0.0.0:8002

and accessing it with http://example.com:8002 should work. 并使用http://example.com:8002访问它应该工作。 But if you only know IP, then launch Django with that IP instead of 但是,如果您只知道IP,那么使用该IP而不是启动Django

0.0.0.0 0.0.0.0

and access it with http://YOUR-IP:8002 并使用http://YOUR-IP:8002访问它

The problem is that django is listening on localhost this means you won't be able to access the server directly via the internet. 问题是django正在监听localhost这意味着你将无法通过互联网直接访问服务器。 To change that you can specify the port/hostname for django: 要更改它,您可以为django指定端口/主机名:

./manage.py runserver 0.0.0.0:8002

If you don't want to make the server directly accessible via the internet you can do port forwarding with ssh: 如果您不想通过互联网直接访问服务器,可以使用ssh进行端口转发:

ssh -L8002:localhost:8002 server

This will forward your local port 8002 via ssh to the remote server. 这将通过ssh将本地端口8002转发到远程服务器。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM