【问题标题】:Running django with uwsgi & nginx error: connect() to unix:/tmp/kb.sock failed运行 django 时出现 uwsgi & nginx 错误:connect() to unix:/tmp/kb.sock failed
【发布时间】:2017-01-30 09:23:20
【问题描述】:

设置一个 django 站点,我可以使用 uwsgi --ini kb_uwsgi.ini --http :8000 在 vi​​rtualenv 之外运行它,但是当我尝试使用 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 初始化

# 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,我考虑尝试使用适当的权限创建它,但这会导致访问错误,这本身可能会诊断出我创建的问题。

【问题讨论】:

  • 替换服务器unix:/tmp/kb.sock;到服务器 unix:///tmp/kb.sock;

标签: django nginx uwsgi


【解决方案1】:

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

并且,阅读此post,使用/var/run 而不是/tmp

【讨论】:

    猜你喜欢
    • 2017-07-30
    • 2018-08-11
    • 2016-02-16
    • 2012-07-10
    • 2020-10-29
    • 2019-08-28
    • 1970-01-01
    • 1970-01-01
    • 2018-04-28
    相关资源
    最近更新 更多