python - uwsgi nginx 连接到 unix 套接字被拒绝

标签 python linux django sockets nginx

我正在尝试将 django 应用程序从 ubuntu 14.04 迁移到 raspberry pi ( raspbian os) 对于 ubuntu,我已经完成了 http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html它奏效了。

在 raspbian 中就没那么简单了。

这是我在/etc/nginx/sites-enabled 中的 bills_nginx.conf

     bills_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
    server unix:/var/www/html/bills/bills/bills.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      80;
    # the domain name it will serve for
    server_name 192.168.5.5; # 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 /var/www/html/bills/bills/bills/media;  # your Django project's media files - amend as required
    }

    location /static {
        alias /var/www/html/bills/bills/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     /var/www/html/bills/bills/uwsgi_params; # the uwsgi_params file you installed
    }
}

这是我的 UWSGI INI 文件:

[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /var/www/html/bills/bills
# Django's wsgi file
module          = bills.wsgi
# the virtualenv (full path)
home            = /home/seb/.virtualenvs/bills3
# process-related settings
# master
master          = true
# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
socket          = /var/www/html/bills/bills/bills.sock
# ... with appropriate permissions - may be needed
uid =www-data
gid=www-data
chown-socket=www-data:www-data
chmod-socket  = 666
# clear environment on exit
vacuum          = true
daemonize=/var/log/uwsgi/bills3.log 
error_log=/var/log/nginx/bills3_error.log

在 error.log 中我得到:

2017/03/08 10:27:43 [error] 654#0: *1 connect() to unix:/var/www/html/bills/bills/bills.sock failed (111: Connection refused) while connecting to upstream, client: 192.168.5.2, server: 192.168.5.5, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:/var/www/html/bills/bills/bills.sock:", host: "192.168.5.5:8000"

请帮我让它工作:)

最佳答案

chmod-socket, chown-socket, gid, uid, 套接字> 要使 uWSGI 和 nginx 通过套接字进行通信,您需要指定套接字的权限和所有者。 777,因为 chmod-socket 对于生产来说过于自由。但是,您可能必须弄乱这个数字才能使其正确,以便所有必要的东西都可以通信。如果您不注意您的套接字配置,您将收到如下错误:

所以确保文件夹的权限.. 我认为更好的方法

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

And change the socket path  

upstream django {
    server unix:/var/uwsgi/bills.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first) }

更多引用:请查看一篇很棒的文章 http://monicalent.com/blog/2013/12/06/set-up-nginx-and-uwsgi/

我也遇到过同样的问题,你可以看看我的配置吗

nginx django uwsgi page not found error

关于python - uwsgi nginx 连接到 unix 套接字被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42669503/

相关文章:

c++ - std::ios_base::Init::Init() 和 std::string::assign(std::string const&) 上的 SIGILL

python - 带有 MySQL 测试的 Django 示例 .travis

django - 包含过滤器中不区分大小写的搜索

python - 如何在 Python 日志记录语句中包含模块的相对路径?

python - 训练后将保存的 NEAT-Python 基因组应用到测试环境

python - pyparsing 的嵌套字典输出

python - Django:静态图像不会加载

python - 扭曲 deferToThread 中的延迟中未处理的错误

linux - snort 和 snort_inline 之间的区别

c++ - 如何使用 C++ 代码设置核心文件名?