{"id":852,"hash":"a39be664ddc45095fe83074010ed4b14e510290db3c8e6c546f4d62d19eadc81","pattern":"(13: Permission denied) while connecting to upstream:[nginx]","full_message":"I am working with configuring Django project with Nginx and Gunicorn.\n\nWhile I am accessing my port gunicorn mysite.wsgi:application --bind=127.0.0.1:8001 in Nginx server, I am getting the following error in my error log file;\n\n  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\"\n\nBelow is the content of my nginx.conf file;\n\nserver {\n    listen 8080;\n    server_name localhost;\n    access_log  /var/log/nginx/example.log;\n    error_log /var/log/nginx/example.error.log;\n\n    location / {\n        proxy_pass http://127.0.0.1:8001;\n        proxy_set_header X-Forwarded-For $remote_addr;\n        proxy_set_header Host $http_host;\n    }\n}\n\nIn the HTML page I am getting 502 Bad Gateway.\n\nWhat mistake am I doing?","ecosystem":"pypi","package_name":"django","package_version":null,"solution":"Disclaimer\nMake sure there are no security implications for your use-case before running this.\n\nAnswer\nI had a similar issue getting Fedora 20, Nginx, Node.js, and Ghost (blog) to work. It turns out my issue was due to SELinux.\n\nThis should solve the problem:\n\nsetsebool -P httpd_can_network_connect 1\n\nDetails\nI checked for errors in the SELinux logs:\n\nsudo cat /var/log/audit/audit.log | grep nginx | grep denied\n\nAnd found that running the following commands fixed my issue:\n\nsudo cat /var/log/audit/audit.log | grep nginx | grep denied | audit2allow -M mynginx\nsudo semodule -i mynginx.pp\n\nOption #2 (probably more secure)\nsetsebool -P httpd_can_network_relay 1\n\nhttps://security.stackexchange.com/questions/152358/difference-between-selinux-booleans-httpd-can-network-relay-and-httpd-can-net\n\nReferences\nhttp://blog.frag-gustav.de/2013/07/21/nginx-selinux-me-mad/\n\nhttps://wiki.gentoo.org/wiki/SELinux/Tutorials/Where_to_find_SELinux_permission_denial_details\n\nhttp://wiki.gentoo.org/wiki/SELinux/Tutorials/Managing_network_port_labels","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/23948527/13-permission-denied-while-connecting-to-upstreamnginx","votes":428,"created_at":"2026-04-19T04:51:49.900635+00:00","updated_at":"2026-04-19T04:51:49.900635+00:00"}