(13:权限被拒绝)连接上游:
我正在用nginx和gunicornconfigurationdjango项目。 当我访问我的端口gunicorn mysite.wsgi:application --bind=127.0.0.1:8001在nginx服务器我在我的错误日志文件中得到以下错误。 
 2014/05/30 11:59:42 [crit] 4075#0: *6 connect() to 127.0.0.1:8001 failed (13: Permission denied) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "localhost:8080" 
 我的nginx.conf文件 
 server { listen 8080; server_name localhost; access_log /var/log/nginx/example.log; error_log /var/log/nginx/example.error.log; location / { proxy_pass http://127.0.0.1:8001; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; } } 
 在html页面,我得到502 Bad Gateway 。 
我在做什么错误?
Fedora 20,Nginx,Node.js和Ghost(博客)都有类似的问题。 事实certificate,我的问题是由于SELinux 。
这应该解决问题:
 setsebool -P httpd_can_network_connect 1 
细节
我检查了SELinux日志中的错误:
 sudo cat /var/log/audit/audit.log | grep nginx | grep denied 
并发现运行以下命令修复了我的问题:
 sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx sudo semodule -i mynginx.pp 
参考文献:
http://blog.frag-gustav.de/2013/07/21/nginx-selinux-me-mad/ https://wiki.gentoo.org/wiki/SELinux/Tutorials/Where_to_find_SELinux_permission_denial_details http://wiki.gentoo .org / wiki / SELinux / Tutorials / Managing_network_port_labels http://www.linuxproblems.org/wiki/Selinux
 我也遇到了这个问题。 另一种解决scheme是切换SELinux的布尔值为httpdnetworking连接on (Nginx使用httpd标签)。 
 setsebool httpd_can_network_connect on 
要使更改保持使用-P标志。
 setsebool httpd_can_network_connect on -P 
您可以看到所有可用的httpd使用的SELinux布尔表
 getsebool -a | grep httpd 
 我已经通过运行我的nginx作为我现在的工作用户mulagala来解决我的问题。默认情况下,用户在我的nginx.conf文件中是nginx 。我们可以在nginx.conf文件的顶部find该行。 
 user nginx; 
将其更改为您当前的工作用户名称
 user mulagala; 
在Centos 7上有类似的问题。当我尝试应用Sorin规定的解决scheme时,我开始循环移动。 首先,我有一个许可{写}拒绝。 然后当我解决了,我有一个许可{connectto}被拒绝。 然后再回到权限{写入}拒绝。
 以上@Sid回答上面的使用getsebool -a | grep httpd检查标志  getsebool -a | grep httpd和切换他们我发现,除了httpd_can_network_connectclosures。  http_anon_write也被closures导致权限被拒绝写入和权限被拒绝{connectto} 
 type=AVC msg=audit(1501830505.174:799183): avc: denied { write } for pid=12144 comm="nginx" name="myroject.sock" dev="dm-2" ino=134718735 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:default_t:s0 tclass=sock_file 
使用sudo cat /var/log/audit/audit.log获取 grep nginx | grep被拒绝,如上所述。
所以我一次一个地解决了他们,一次一个切换一个标志。
 setsebool httpd_can_network_connect on -P 
然后运行上面@sorin和@Joseph指定的命令
 sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx sudo semodule -i mynginx.pp 
基本上你可以检查在setsebool上设置的权限,并将其与grepp'ing'audit.log nginx获得的错误相关联,否认
我也遇到了这个问题。 我使用HHVM的Nginx,下面的解决scheme解决了我的问题:
 sudo semanage fcontext -a -t httpd_sys_rw_content_t "/etc/nginx/fastcgi_temp(/.*)?" sudo restorecon -R -v /etc/nginx/fastcgi_temp 
 sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx sudo semodule -i mynginx.pp