且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

连接到服务器上运行的 virtualenv/django 时如何解决 ERR_CONNECTION_REFUSED

更新时间:2022-10-15 18:47:42

问题出在 virtualenv 中,它以某种方式阻止了连接(找不到).我停用了 virtualenv 并使用 python3 manage.py runserver 0.0.0.0:8000 启动了该应用程序.该应用程序应该可以通过 http://[ ip ]:8000 访问,其中 ipipconfig getifaddr en0 命令返回的内容.>

您还可以使用 gunicorn 来托管应用程序 &nginx 提供静态文件(因为 gunicorn 不处理).这将允许继续使用 virtualenv,但会带来使用更多软件的需要.

I have installed virtualenv and Django in my user section on a ubuntu server. Everything appeared to install correctly and when I start the server with python manage.py runserver I get the following message, which seems correct:

Performing system checks...

System check identified no issues (0 silenced).

You have 15 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes,                                                                       sessions.
Run 'python manage.py migrate' to apply them.

January 10, 2019 - 16:38:32
Django version 2.1.5, using settings 'form01.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

The problem is when I go to http://127.0.0.1:8000/ in my browser I get an ERR_CONNECTION_REFUSED instead of the Django install success page.

I expect to see the Django successful install screen at http://127.0.0.1:8000 but instead get ERR_CONNECTION_REFUSED.

The problem is in virtualenv, it blocks connection somehow (couldn't find it out). I deactivated virtualenv and launched the app using python3 manage.py runserver 0.0.0.0:8000. The app should be accessible on http://[ ip ]:8000 where ip is the thing returned by ipconfig getifaddr en0 command.

You can also use gunicorn to host the app & nginx to deliver static files (as gunicorn doesn't handle that). This will allow to continue use the virtualenv, but will bring the need to use some more software.