Python+uWSGI+nginx报错:Permission denied


折腾我好久了,老是提示没有权限:


 -bash-4.1# > /var/log/nginx/error.log 
-bash-4.1# curl 127.0.0.1:8080
<html>
<head><title>502 Bad Gateway</title></head>
<body bgcolor="white">
<center>

<h1>502 Bad Gateway</h1>

</center>


<hr>

<center>nginx/1.6.2</center>
</body>
</html>

-bash-4.1# cat /var/log/nginx/error.log 
2015/01/16 18:51:32 [crit] 4937#0: *1 connect() to 127.0.0.1:3301 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: uwsgi_demo, request: "GET / HTTP/1.1", upstream: "uwsgi://127.0.0.1:3301", host: "127.0.0.1:8080"

测试程序:


 def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return ['Hello World']

测试程序目录情况:


 -bash-4.1# ll
total 12
-rw-r--r--. 1 nginx nginx 139 Jan 16 15:34 app.py
-rw-r--r--. 1 root  root  136 Jan 16 18:37 demo.ini
-rw-r-----. 1 root  root   95 Jan 16 18:45 demo.log

uswgi 配置:


 [uwsgi]
socket = 127.0.0.1:3031
wsgi-file = app.py

uid = nginx
gid = nginx
chmod-socket = 666

logto = demo.log
stats = 127.0.0.1:9191

nginx配制:


 server {
    listen      8080;
    server_name uwsgi_demo;
    location / {
        include uwsgi_params;
        uwsgi_pass 127.0.0.1:3301; 
    }
}

进程情况:


 -bash-4.1# ps aux | grep nginx
nginx     4819  0.0  0.3  53996  6852 pts/4    S+   18:48   0:00 uwsgi26 demo.ini
nginx     4821  0.0  0.3  73460  6048 pts/4    S+   18:48   0:00 uwsgi26 demo.ini
root      4935  0.0  0.1 141788  2568 ?        Ss   18:50   0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     4937  0.0  0.1 142184  3292 ?        S    18:50   0:00 nginx: worker process                   
root      4939  0.0  0.0   6380   692 pts/2    S+   18:50   0:00 grep nginx

python nginx uwsgi

JrSeven 10 years ago

connect 到本地端口失败,应该是被 SELinux 之类的拒绝了吧?设置正确的访问控制规则即可。

Kwinmax answered 10 years ago

禁止访问应该是设置的根目录造成的

傲娇海绵体先生 answered 10 years ago

解决了,是nginx访问目录权限问题吧。不过不知道为什么用 yum 安装的nginx,如果把网站目录放在其他地方,总是提示禁止访问。所以只好自己编译安装nginx,另外存放网站的目录包括父目录,一定要有可执行权限。
不知道是不是这样,反正现在可以了。

鬼畜二小姐 answered 10 years ago

Your Answer