【发布时间】:2014-03-31 01:39:41
【问题描述】:
嗯,我目前正在尝试使用 nginx 和 uwsgi 提供我的 django 应用程序。我目前正在使用安装了 uwsgi 的虚拟环境。但是,我目前在尝试访问该页面时收到 502 bad gateway 错误。
我遇到的错误。
2014/02/27 14:20:48 [crit] 29947#0: *20 connect() to unix:///tmp/uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: 144.136.65.176, server: domainname.com.au, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///tmp/uwsgi.sock:", host: "www.domainname.com.au"
这是我的 nginx.conf
# mysite_nginx.conf
# the upstream component nginx needs to connect to
upstream django {
server unix:///tmp/uwsgi.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 .domainname.com.au; # 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/deepc/media; # your Django project's media files - amend as required
}
location /static {
alias /home/deepc/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/deepc/.virtualenvs/dcwebproj/dcweb/uwsgi_params; # the uwsgi_params file you installed
}
}
这是我的 uwsgi.ini 文件
[uwsgi]
socket=/tmp/uwsgi.sock
chmod-socket=644
uid = www-data
gid = www-data
chdir=/home/deepc/.virtualenvs/dcwebproj/dcweb
module=dcweb.wsgi:application
pidfile=/home/deepc/.virtualenvs/dcwebproj/dcweb.pid
vacuum=true
从我在谷歌上读到的内容来看,它是 www-data 组和 /tmp/ 目录的权限问题。但是我对此并不陌生,并试图更改文件夹的权限级别无济于事。有人能指出我正确的方向吗?这是权限问题吗?
也可以把sock文件放到tmp目录下吗?
谢谢
【问题讨论】:
-
尝试将
chmod-socket=644更改为666?我不确定 -
原因是nginx无法访问sock文件。确保启动 uwsgi 的用户组与 nginx 组(默认 www-data)相同,以便 nginx 可以访问 sock 文件,然后一切正常。
usermod -g www-data username。希望有帮助