Fixing nginx “13: Permission Denied” on RHEL 8 with SELinux
Allow nginx to bind to a non-standard port on RHEL 8 by adding the appropriate SELinux port label.
When nginx is configured to listen on a non-standard port such as 1080 on RHEL 8, it may fail with 13: Permission denied. SELinux port labeling is a common cause.
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 allows nginx to bind to the non-standard port on RHEL 8.
Although the message resembles a file-permission error, SELinux denies the bind operation when the port is not labeled with a type that nginx may use.
When adding another non-standard listening port on an SELinux-enforcing host, check its SELinux port label before changing file permissions or firewall settings.
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.
Improving Cross-Team Communication with C4 Diagrams
Learn the characteristics of the C4 model, how it differs from UML and infrastructure diagrams, and how to communicate architecture at the right level for each role.
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
Containerizing a FastAPI backend and deploying it to a single Lambda function with Lambda Web Adapter and AWS CDK.
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.
