Fixing nginx “13: Permission Denied” Error on RHEL8 with SELinux
Fix nginx Permission denied when proxying to a non-standard port by adjusting SELinux settings.
When configuring nginx to route traffic to a non-standard port such as 1080 on an instance, you may encounter the error 13: Permission denied. This issue often arises due to SELinux restrictions.
systemd[1]: Starting The nginx HTTP and reverse proxy server...nginx[1626]: nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx[1626]: nginx: [emerg] bind() to 0.0.0.0:1080 failed (13: Permission denied)nginx[1626]: nginx: configuration file /etc/nginx/nginx.conf test failedsystemd[1]: nginx.service: Control process exited, code=exited status=1systemd[1]: nginx.service: Failed with result 'exit-code'.systemd[1]: Failed to start The nginx HTTP and reverse proxy server.Solution
The fix is to allow nginx to use the custom port 1080 by updating SELinux policies:
sudo semanage port -a -t http_port_t -p tcp 1080If you encounter the error sudo: semanage: command not found, install the required package with these commands:
sudo dnf provides /usr/sbin/semanagesudo dnf install policycoreutils-python-utilsConclusion
Labeling port 1080 as http_port_t with semanage port resolved nginx’s 13: Permission denied error when binding to that non-standard port on RHEL8. The error message looks identical to a firewall or file-permissions problem, but on RHEL8 with SELinux enforcing, it usually just means the port hasn’t been labeled as a type nginx is allowed to bind to. semanage port -a -t http_port_t -p tcp 1080 fixes it in one line once that’s understood, and the same command is worth reaching for immediately any time a new non-standard port gets added to an nginx config on an SELinux-enforced host, rather than re-diagnosing the same error from scratch.
Related posts
Running Proxy.py as a Lightweight HTTP Proxy on EC2
Running Proxy.py on an EC2 instance and reaching it safely through an SSH tunnel, since the proxy has no authentication of its own.
Sign in with Slack Using Cognito User Pools and OIDC
Federating Cognito user pools with Slack over OIDC and wiring "Sign in with Slack" into a Next.js app with Amplify.
Deploying FastAPI on AWS Lambda with Lambda Web Adapter
This example guides you through the process of developing API backends with FastAPI using Lambda Web Adapter.
API Gateway WebSocket: Implementing a Mock Integration
Building an API Gateway WebSocket API entirely with mock integrations, returning canned responses with no backend Lambda involved.
Uploading to S3 Through CloudFront Pre-Signed URLs
CloudFront signed URLs let you upload to S3 through a custom domain—useful when direct S3 pre-signed URLs are not an option.
