CentOS 7 中Nginx proxy 502的问题

环境 CentOS Linux release 7.0.1406 (Core)     Nginx    tomcat

使用nginx做前端,proxy后端tomcat 8080 端口,浏览器死活502 ,⊙︿⊙。

stackoverflow 上发现同样有人遇到此问题,

http://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx

翻阅了Nginx的blog

http://nginx.com/blog/nginx-se-linux-changes-upgrading-rhel-6-6/

此问题在6.6以上就出现了,sudo cat /var/log/audit/audit.log | grep nginx | grep denied

查阅SELinux 日志,发现问题

type=AVC msg=audit(1420460715.553:594): avc:  denied  { name_connect } for  pid=3425 comm=”nginx” dest=8080 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_cache_port_t:s0 tclass=tcp_socket

 

执行命令(yum -y install policycoreutils-python)

sudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx
sudo semodule -i mynginx.pp

搞定,502请滚粗……