用uwsgi&运行django nginx错误:connect()到unix:/tmp/kb.sock失败

时间:2017-01-30 09:23:21

标签: django nginx uwsgi

设置django站点,我可以在virtualenv之外使用uwsgi --ini kb_uwsgi.ini --http :8000运行它,但是当我尝试使用nginx设置它时会在日志中出现错误:

2017/01/30 08:00:26 [crit] 24629#24629: *1 connect() to unix:/tmp/kb.sock failed (2: No such file or directory) while connecting to upstream, client: 197.232.12.165, server: kenyabuzz.nation.news, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/tmp/kb.sock:", host: "kenyabuzz.nation.news"

这里是nginx文件

# kb.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:/tmp/kb.sock; # for a file socket
    #server 0.0.0.0:8000; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen 0.0.0.0:80;
    # the domain name it will serve for
    server_name kenyabuzz.nation.news; # 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/ubuntu/webapps/kenyabuzz/kb/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /home/ubuntu/webapps/kenyabuzz/kb/static; # your Django project's static files - amend as required
    }

    location /favicon.ico {
        alias /home/ubuntu/webapps/kenyabuzz/kb/static/kb/favicon.ico; # favicon
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/ubuntu/webapps/kenyabuzz/uwsgi_params; # the uwsgi_params file you installed
    }
}

uwsgi ini

# kb_uwsgi.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/ubuntu/webapps/kenyabuzz
# Django's wsgi file
module          = kb.wsgi
# the virtualenv (full path)
home            = /home/ubuntu/webapps/djangoenv

# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /tmp/kb.sock
# ... with appropriate permissions - may be needed
chmod-socket    = 664

# clear environment on exit
#vacuum          = true

和uwsgi_params

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param  REQUEST_METHOD     $request_method;
uwsgi_param  CONTENT_TYPE       $content_type;
uwsgi_param  CONTENT_LENGTH     $content_length;

uwsgi_param  REQUEST_URI        $request_uri;
uwsgi_param  PATH_INFO          $document_uri;
uwsgi_param  DOCUMENT_ROOT      $document_root;
uwsgi_param  SERVER_PROTOCOL    $server_protocol;
uwsgi_param  REQUEST_SCHEME     $scheme;
uwsgi_param  HTTPS              $https if_not_empty;

uwsgi_param  REMOTE_ADDR        $remote_addr;
uwsgi_param  REMOTE_PORT        $remote_port;
uwsgi_param  SERVER_PORT        $server_port;
uwsgi_param  SERVER_NAME        $server_name;

该文件不存在kb.sock我认为尝试使用适当的权限创建该文件但会导致访问错误本身可能会导致我创建的问题。

1 个答案:

答案 0 :(得分:0)

我认为你应该使用unix://而不是unix:

并且,请阅读此post,使用/var/run代替/tmp