How to Solve nginx "13: Permission denied" on RHEL8
Takahiro Iwasa
2 min read
nginx
It has been more than 3 years since this post was published.
When routing traffic to port 1080
using nginx on an EC2 RHEL8 instance, I encountered an error message saying 13: Permission denied
.
This issue is related to SELinux.
Situation
URL Copied!
I added the following lines to nginx.conf
file.
The example below uses nginx.conf
file directly for simple description.
diff -U3 nginx.conf.old nginx.conf
--- nginx.conf.old 2021-08-27 23:04:42.527667800 +0900
+++ nginx.conf 2021-08-28 01:20:38.088408400 +0900
@@ -45,6 +45,12 @@
include /etc/nginx/default.d/*.conf;
location / {
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+ proxy_set_header X-Forwarded-Host $host;
+ proxy_set_header X-Forwarded-Server $host;
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_pass http://xxx.xxx.xxx.xxx:1080;
}
error_page 404 /404.html;
Then, I encountered the following error.
systemd[1]: Starting The nginx HTTP and reverse proxy server...
nginx[1626]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx[1626]: nginx: [emerg] bind() to 0.0.0.0:1080 failed (13: Permission denied)
nginx[1626]: nginx: configuration file /etc/nginx/nginx.conf test failed
systemd[1]: nginx.service: Control process exited, code=exited status=1
systemd[1]: nginx.service: Failed with result 'exit-code'.
systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Solution
URL Copied!
I was able to solve the issue with the following command.
sudo semanage port -a -t http_port_t -p tcp 1080
If you see sudo: semanage: command not found
, install it with the following command.
sudo dnf provides /usr/sbin/semanage
sudo dnf install policycoreutils-python-utils