gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:41:09 25 4
gpt4 key购买 nike

我正在尝试将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com