Fix Rocky 9 nginx bind() to 8081 failed (13: Permission denied)
Rocky 9 nginx "bind() to 0.0.0.0:8081 failed (13: Permission denied)": if SELinux is enforcing and logs a name_bind AVC, label the port http_port_t.
2026/10/26 21:51:32 [emerg] 190#190: bind() to 0.0.0.0:8081 failed (13: Permission denied)13: Permission denied means the kernel refused to bind that port. On Rocky 9, if SELinux is Enforcing and a name_bind denial (AVC) for nginx was logged, nginx tried to bind a port without the http_port_t label, and labeling it with semanage port fixes it. Without that record, SELinux is not the cause — the output above was itself produced in a container with SELinux off, by a different cause (the unprivileged port floor), with identical wording. So tell them apart with [1] and [2] first. A port already in use by another process gives a different message, 98: Address already in use.
[1] Check whether SELinux is enforcing. If it says Enforcing, go to [2].
# getenforceIf it is Disabled or Permissive and you still get 13, SELinux is not the cause. The output above was in fact produced in a container with SELinux off, by running nginx as a regular user with the unprivileged port floor (ip_unprivileged_port_start) raised to 9000. The message is identical. If nginx runs as a non-root user, or the container sets a port floor, look there instead.
[2] Look for the denial (AVC). Search right after starting nginx once more to trigger the error.
# ausearch -m AVC -ts recent -c nginxContinue to [3] only if a line matches all four items below. It has the same shape as the port-denial example in the RHEL 9 docs (httpd, 9876) (RHEL 9 SELinux troubleshooting).
| Item | Expected value |
|---|---|
| Denied permission | avc: denied { name_bind } |
| Process | comm="nginx" · scontext=…:httpd_t:… |
| Port | src=8081 (the port you configured) |
| Target | tclass=tcp_socket |
[3] See which label the port has now. If semanage is missing, install the policycoreutils-python-utils package first (also a prerequisite in the RHEL 9 docs). Minimal installs and container images do not include it.
# command -v semanage || echo "semanage: not found"semanage: not found# dnf install policycoreutils-python-utils# rpm -qf "$(command -v semanage)"policycoreutils-python-utils-3.6-5.el9.noarchStart with the list nginx may use:
# semanage port -l | grep -w http_port_thttp_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 90008081 is not in it; it is already bound to another type:
# semanage port -l | grep -E "[ ,]8081(,|$)"transproxy_port_t tcp 8081[4] Before changing anything, save the current local rules to a file. You will need it to revert. If it is empty (lines=0), as below, there are no local rules yet.
# semanage port -l -C > /root/port-local-before.txt; cat /root/port-local-before.txt; echo "lines=$(wc -l < /root/port-local-before.txt)"lines=0Then add the port to http_port_t. The RHEL 9 SELinux guide uses the same command for a non-standard port (RHEL 9 Using SELinux; its example is httpd on port 3131). For a port already defined under another type, like 8081, this version switches to modify on its own. Both this automatic modify and -m overwrite any local rule the port had — which is why you saved the file first.
# semanage port -a -t http_port_t -p tcp 8081Port tcp/8081 already defined, modifying insteadUsing modify (-m) from the start does the same thing and prints nothing:
# semanage port -m -t http_port_t -p tcp 8081A port that is not defined anywhere (8088 in the test) is simply added by -a.
[5] Verify the change. -C shows only your local additions, not the base policy.
# semanage port -l -CSELinux Port Type Proto Port Number http_port_t tcp 8081# semanage port -l | grep -E "[ ,]8081(,|$)"http_port_t tcp 8081, 80, 81, 443, 488, 8008, 8009, 8443, 9000transproxy_port_t tcp 8081The base policy's transproxy_port_t line is still listed. Confirm with nginx itself: run systemctl restart nginx, and when ss -ltnp | grep 8081 shows nginx, you are done. If remote clients still cannot connect, the firewall is next (open a port with firewalld).
[6] To revert, check the file saved in [4] and pick one of two paths.
If the file was empty (no local rules before), delete with -d. The base policy's transproxy_port_t stays.
# semanage port -d -t http_port_t -p tcp 8081# semanage port -l | grep -E "[ ,]8081(,|$)"transproxy_port_t tcp 8081If the file had a local rule for that port, -d does not bring it back (-d only deletes). Below, 8081 originally had a local websm_port_t rule. After the change, -l -C showed http_port_t in its place; putting back the type from the file with -m restored it.
# semanage port -l -C | tee /root/port-local-before.txtSELinux Port Type Proto Port Number websm_port_t tcp 8081# semanage port -m -t websm_port_t -p tcp 8081 && semanage port -l -CSELinux Port Type Proto Port Number websm_port_t tcp 8081If the port is fixed but the proxy returns 502, see the boolean in Nginx proxy blocked by SELinux; if a new document root returns 403, see SELinux file labels.
Analyze your Nginx log in the browser ↗ — nothing is uploaded.