【问题标题】:Cannot connect Nginx with uwsgi +Django无法将 Nginx 与 uwsgi +Django 连接
【发布时间】:2017-11-07 01:42:07
【问题描述】:

我尝试过的: 1、Nginx没问题,可以访问80端口,看默认页面 2. uwsgi + django 很好,我可以使用 uwsgi 启动我的 django 应用并访问它 ,用命令:

uwsgi --http :8000 --module webapps.wsgi

当我将uwsgi连接到nginx时出现问题

2017/11/07 01:36:47 [error] 27958#27958: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 71.61.176.181, server: 104.196.31.159, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:8001", host: "104.196.31.159:8000"

这里是 nginx 的 mysite.conf

# mysite_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    #server unix:///home/liuziqicmu/ziqil1/homework/6/mysite.sock; # for a file socket
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      8000;
    # the domain name it will serve for
    server_name xx.xx.xx.xx(my ip); # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {
        alias /home/liuziqicmu/ziqil1/homework6/grumblr/upload;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/liuziqicmu/ziqil1/homework6/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/liuziqicmu/ziqil1/homework/6/env/uwsgi_params; # the uwsgi_params file you installed
    }
}

我启动它的命令:

uwsgi --socket 8001 --module webapps.wsgi

另外,当我运行 nginx -t 时,它显示:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2017/11/07 02:02:13 [warn] 19350#19350: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2017/11/07 02:02:13 [emerg] 19350#19350: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed

这会是个问题吗?

【问题讨论】:

    标签: django nginx uwsgi


    【解决方案1】:

    确保/var/log/nginx/run存在并且可以被nginx写入

    【讨论】:

    • 我通过将 mysite.conf 复制到 /etc/nginx/sites-enabled/ 解决了这个问题。以前我只是 ln -s 到那条路径,但谁能告诉我为什么软链接不起作用?
    猜你喜欢
    • 2019-03-03
    • 1970-01-01
    • 2015-04-30
    • 2011-11-25
    • 2015-11-25
    • 2015-12-29
    • 2017-07-22
    • 2014-02-01
    • 2014-05-31
    相关资源
    最近更新 更多