【问题标题】:Can't access Django site in production无法在生产中访问 Django 站点
【发布时间】:2018-04-02 04:22:47
【问题描述】:

我无法在生产环境中访问我的 Django 网站。它返回“ERR_CONNECTION_REFUSED”。

编辑:我的错误是:

File "/home/chuck/sitepro/site/sitepro/wsgi.py", line 12, in <module>
    from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi

我在 Ubuntu 16.04 中使用 Nginx + Gunicorn + Supervisor。

这是我的 sitepro.conf(主管)

[program:sitepro]
command = /home/chuck/sitepro/bin/gunicorn sitepro.wsgi:application -w 4 -b :8002 --$
directory = /home/chuck/sitepro/site/sitepro
user = chuck
stdout_logfile = /home/chuck/sitepro/site/logs/gunicorn/gunicorn_stdout.log
stderr_logfile = /home/chuck/sitepro/site/logs/gunicorn/gunicorn_stderr.log
redirect_stderr = True
environment = PRODUCTION=1

还有我的 Nginx 配置文件:

server {
    listen 80;
    server_name www.mywebsite.com;
    return 301 https://www.mywebsite.com$request_uri;
}

server {
    listen 443 ssl;
    server_name mywebsite.com;
    root /home/chuck/sitepro/site;

    access_log /home/chuck/sitepro/site/logs/nginx/access.log;
    error_log /home/chuck/sitepro/site/logs/nginx/error.log;

    location / {
        proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        if (!-f $request_filename) {
            proxy_pass http://127.0.0.1:8002;
            break;
        }
    }
}

我的根文件夹在 /home/chuck/sitepro/site/ 中,sitepro 是我的主要应用程序,包含 Django 默认的 wsgi.py。

ufw 中的 8002 端口是开放的。日志为空。

我错过了什么吗?

谢谢:)

【问题讨论】:

  • 您在 Nginx 错误日志/home/chuck/sitepro/site/logs/nginx/error.log 中看到任何错误吗?
  • 不抱歉文件是空的:/
  • 你的 nginx 服务器上的端口是否开放?如果您在 nginx 日志中没有看到任何内容,那会让我相信在连接到 nginx 之前出现了问题。
  • 你能 ssh 进入主机然后 curl localhost:8001 吗?实际上,如果您的 nginx 日志是空的,那么请求甚至没有达到那么远,您可能正在查看防火墙问题。你也尝试过 http 和 https 请求吗?
  • 我的端口是开放的。我只是尝试启动 gurnicon 本地命令: gunicorn wsgi.py:application --bind :8002 我有:

标签: python django nginx gunicorn


【解决方案1】:

我发现了我的问题:我做了一个“pip install django”,它现在可以工作了。 感谢所有评论员的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多