【问题标题】:nginx django uwsgi page not found errornginx django uwsgi页面未找到错误
【发布时间】:2017-07-17 19:56:19
【问题描述】:

我正在尝试在 Nginx 上设置 uwsgi 和 Django,但显示页面未找到错误并且错误日志为空。 我无法识别错误,因为错误日志为空。

错误日志/var/log/nginx/error.log:

-rw-r--r-- 1 www-data root 0 Feb 26 12:31 error.log

uswgi 运行正常,因为我在以下方法上对此进行了测试:

uwsgi --http :8080 --home /home/flybegins/python/django/venv/ --chdir /home/flybegins/python/django/sample -w sample.wsgi

virtual host 

    server {
        listen 80;
        server_name test.aaaaaaa.com;
        error_log  /var/log/nginx/error.log
        location /static/ {
            root /home/flybegins/python/django/sample/
        }

        location / {
            include         uwsgi_params;
            uwsgi_pass      unix:/home/flybegins/python/django/sample/sample.sock;
        } }

虚拟主机权限:

-rw-r--r-- 1 root root 333 Feb 27 08:54 test.aaaa.com

提前致谢!

【问题讨论】:

  • 你使用的是什么操作系统?
  • 感谢@Os - ubuntu 4.9.7-x86_64-linode80

标签: python django nginx uwsgi


【解决方案1】:

你需要为uwsgi安装python插件

sudo apt-get install uwsgi-plugin-python

或者对于 python 3

sudo apt-get install uwsgi-plugin-python3

【讨论】:

  • 感谢您的回复.. 不幸的是仍然相同的结果,为什么错误日志是空的,我如何追踪 nginx 上的错误.....
【解决方案2】:

您正在使用以下代码使用端口 8080 运行您的项目:

uwsgi --http :8080 --home /home/flybegins/python/django/venv/ --chdir /home/flybegins/python/django/sample -w sample.wsgi

您正在尝试使用此配置将 NGINX 绑定到不存在的套接字文件:

location / {
            include         uwsgi_params;
            uwsgi_pass      unix:/home/flybegins/python/django/sample/sample.sock;
        }

这就是为什么它不起作用。

【讨论】:

    【解决方案3】:

    我犯了两个错误一个是nginx虚拟主机配置另一个是socket权限错误

    uWSGI 配置

    [uwsgi]
    project = prd
    base = /home/flybegins/python/django
    
    chdir = %(base)/%(project)
    home = %(base)/venv
    module = %(project).wsgi:application
    
    master = true
    processes = 5
    
    gid = www-data
    uid = www-data
    
    socket = /var/uwsgi/%(project).sock
    chmod-socket = 664
    vacuum = true
    

    要为套接字创建空间,您只需选择一个持久目录(例如,不是 /run 或 /tmp)并将 www-data(用户 nginx 运行为)它的所有者,如下所示:

    $ sudo mkdir /var/uwsgi
    $ sudo chown www-data:www-data /var/uwsgi
    

    我的 nginx 虚拟主机配置

    server {
        listen 80;
        server_name testserver1.com;
        access_log /home/flybegins/log/python/testserver1.com/access.log;
        error_log /home/flybegins/log/python/testserver1.com/error.log error;
    
     location  /static {
          alias  /home/flybegins/python/django/prd/static_files/;
        }
    
      location / {
            include         uwsgi_params;
            uwsgi_pass      unix:/var/uwsgi/prd.sock;
        }
    
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-01
      • 2013-07-30
      • 2016-02-16
      • 2018-08-11
      • 2014-08-03
      • 2012-07-10
      • 2018-11-12
      • 2012-08-02
      • 2021-02-01
      相关资源
      最近更新 更多