Australian cloud for business software — built and run in Sydney since 2002

NetLeverage
NetLeverage

SELinux blocks the web server: "avc: denied", httpd_can_network_connect and port labels

Technical article
Troubleshooting

About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.

If the audit log holds a line starting type=AVC ... avc: denied for a process running as httpd_t, SELinux policy refused the action, whatever the file permissions say. For a web server two documented fixes are a boolean (for example httpd_can_network_connect when Apache must connect out to a backend) and a port label (semanage port when it must listen on a new port). Read the denial first. Do not switch SELinux off to make the error go away.

What the symptom means

SELinux decisions are cached in the Access Vector Cache (AVC), and denials are written to /var/log/audit/audit.log. Red Hat's guide explains the fields of a denial. avc: denied is the action taken. The braces hold the denied permission. comm= is the command, scontext is the label of the process (here a type ending in httpd_t), tcontext is the label of the thing it tried to reach, and tclass is the kind of object.

The permission tells you which of three problems you have:

  • A file or directory permission such as read or getattr, where tcontext shows an unexpected type. That is a labelling fault. The page titled "SELinux labels after a restore: why services get "permission denied" and how relabelling works" covers it.
  • name_bind on a tcp_socket: the process tried to listen on a port whose label policy does not allow. Red Hat's example is Apache set to Listen 9876, which makes systemctl start httpd.service fail.
  • name_connect on a tcp_socket: the process tried to connect out to a port. The SELinux Notebook describes name_connect for TCP as connecting "to a specific port type."

The policy has switches for particular cases, called booleans. In the upstream Reference Policy source, the boolean httpd_can_network_connect is described as "Determine whether httpd scripts and modules can connect to the network using TCP", and it is off by default. When on, the source lets httpd_t connect to all TCP ports. Narrower booleans exist, such as httpd_can_network_connect_db for databases, which Red Hat uses as its own example for letting Apache talk to MariaDB.

Likely causes

Cause What you see How to confirm
Web server or PHP code connects out (proxy, API, mail relay) Backend calls fail; denial with name_connect, tclass=tcp_socket, scontext with httpd_t ausearch shows the denial; getsebool httpd_can_network_connect says off
Web server set to listen on a non-standard port systemctl start fails with "Job for httpd.service failed"; denial with name_bind semanage port -l | grep http does not list the port
Wrong file label Denial with read or getattr and a tcontext type such as samba_share_t or user_home_t Compare tcontext with the type of the web content directory
Another feature boolean is off Denial on NFS or CIFS content getsebool -a | grep httpd shows httpd_use_nfs or httpd_use_cifs as off
Denial hidden by a dontaudit rule Application fails, audit log silent Red Hat's steps: check journalctl -t setroubleshoot, then run semodule -DB temporarily (see the Risk note that follows the checks)
Not SELinux No matching denial, even after the previous checks getenforce and the audit search return nothing relevant

Prove the cause before changing anything

All of these read only, except where noted.

getenforce
ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent -i

getenforce returns Enforcing, Permissive or Disabled, per Red Hat. Red Hat uses ausearch to list denials. -ts recent means the last 10 minutes (the manual defines "Recent is 10 minutes ago"), and -i interprets numeric fields into text. Reproduce the failure first, then run it. If ausearch shows nothing, Red Hat's next steps are to confirm that auditd is running, then try journalctl -t setroubleshoot, and, if the audit daemon is not running, dmesg | grep -i -e type=1300 -e type=1400.

To have the tools explain a denial in words:

ausearch -m AVC -ts recent --raw | audit2allow -w

The audit2allow manual says -w "translates SELinux audit messages into a description of why the access was denied", and Red Hat pipes ausearch --raw into audit2allow in the same way when it builds a module (audit2allow -D -M, -M) or, in an example without --raw, asks for rule suggestions (-R). Red Hat's own text also names audit2allow -w -a as output to include in a support case. The manual also warns that the tool generates only type-enforcement allow rules and that care "must be exercised while acting on the output of this utility", because the suggestion can be broader than you want.

Then check the boolean and the port labels:

getsebool -a | grep httpd
semanage port -l | grep http

getsebool -a lists every boolean with its state. semanage port -l lists port labels. Red Hat's sample output in its Port numbers section shows http_port_t tcp 80, 443, 488, 8008, 8009, 8443, and its section 4.1 (Apache on port 3131) shows a different sample, http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000. Your list may differ from both. To read what each boolean means, Red Hat says to install selinux-policy-devel and run semanage boolean -l as root.

Risk: Red Hat's last step for a silent denial is semodule -DB, which "temporarily disable[s] dontaudit rules, allowing all denials to be logged". The audit log then receives denials that the policy deliberately silences, so expect more log entries. To back out, run semodule -B, which Red Hat says "enables dontaudit rules in the policy again". Run it as soon as you have the denial.

Do not use permissive mode as a fix. Red Hat says permissive mode is "not recommended for production systems" but "helpful for SELinux policy development and debugging". If you must test whether SELinux is the cause, the narrower option Red Hat documents is a permissive domain, semanage permissive -a httpd_t, with the warning that permissive domains "can compromise security of your system".

Risk: semanage permissive -a httpd_t makes the web server domain permissive, so SELinux logs what it would have blocked but no longer blocks it. While the record exists the web server is not confined by SELinux. Use it for one reproduction and remove it at once. To back out, run semanage permissive -d httpd_t. The semanage-permissive manual says -d removes a record of the specified type, and that it can only remove the permissive property from domains where it was added by semanage permissive; semanage permissive -l lists the "Customized Permissive Types".

Example (illustrative): web01 runs Apache as a reverse proxy to an application server at 203.0.113.20 on TCP port 8081. After a policy update, requests return an error page. ausearch ... -i shows one denial: comm="httpd", scontext containing httpd_t, tclass=tcp_socket, permission name_connect. getsebool httpd_can_network_connect prints httpd_can_network_connect --> off. The administrator chooses the boolean, runs one test request, and re-runs ausearch to confirm there is no new denial.

Fix

Outbound connections: set the boolean

setsebool -P httpd_can_network_connect on

The setsebool manual says that without -P "only the current boolean value is affected" and the boot-time default is not changed. With -P, "all pending values are written to the policy file on disk", so the setting persists across reboots. Red Hat notes that a setsebool -P command rebuilds the entire policy and might take some time.

Risk: this boolean is broad. In the upstream source it grants httpd_t TCP connections to all ports, so a compromised web application could reach any internal service. Prefer a narrower boolean when one fits: httpd_can_network_connect_db for database servers. The upstream source also defines httpd_can_network_relay, which allows connections to port types for gopher, ftp, http, http cache and squid. To back out, run setsebool -P httpd_can_network_connect off.

Listening on a new port: label the port

semanage port -a -t http_port_t -p tcp 9876

Red Hat's explanation: -a adds a record, -t sets the type, -p the protocol, and the last argument is the port number. The semanage-port manual has the same pattern with TCP port 81. Pick the type that matches the service, and change nothing else about the port. Risk: every process allowed to use http_port_t can now use that port. To back out, delete the record with semanage port -d -p tcp 9876; the semanage-port manual lists --delete -p PROTOCOL port_name. List your own additions first with semanage port -l -C, which the manual describes as listing local customisations.

File labels and other booleans

For label faults, use the relabelling steps in the page titled "SELinux labels after a restore: why services get "permission denied" and how relabelling works". For NFS or CIFS content, Red Hat's example enables httpd_use_nfs and httpd_use_cifs with setsebool.

Risk: a boolean is a policy change that applies to every process in the web server domain. To back out, set the boolean to off with the same command; the setsebool manual says the value may be 0, false or off to disable it, and that -P writes the value so it persists across reboots.

Do not paste the audit2allow module blindly

audit2allow can create a custom policy module. Red Hat's guide warns that it "does not support creating SELinux policy modules with custom rules" in its production support scope and says to use only rules provided by Red Hat. Use a boolean or a port label when one exists.

Confirm the fix

  1. Repeat the exact action that failed.
  2. ausearch -m AVC,USER_AVC,SELINUX_ERR,USER_SELINUX_ERR -ts recent -i returns no new denial for the process. Red Hat's own check for this ends with <no matches>.
  3. getsebool httpd_can_network_connect (or the boolean you used) reports on, and semanage port -l | grep http lists the new port where relevant.
  4. Reboot-safe: if you used setsebool without -P, the setting is gone after restart. Check the persistent value.

What to watch afterwards

  • New denials after package or policy updates. Red Hat notes that policy evolves and an updated application may need actions the current policy does not account for.
  • Which booleans differ from defaults on each server, so the setting is part of the build and not a hidden fix.
  • Any web content moved between directories or restored from backup, which brings back label faults.

Risks and limits

  • These commands have not been run or lab-tested. They are taken from the Red Hat guide and the manual pages cited in Sources.
  • The Red Hat guide used is the RHEL 9 text. Other versions, and other distributions that use SELinux, can differ.
  • The statements about what each boolean permits come from the upstream Reference Policy source. Red Hat and other distributions ship their own policy, so confirm with semanage boolean -l on your server.
  • A boolean is a policy change on a production system. Make it on one server first, and record it.
  • Only the web server domain is covered here. It does not cover containers, confined users or MLS policy.

Sources

  • Using SELinux, RHEL 9 — Red Hat documentation, no date shown; Internet Archive copy of 4 February 2026, accessed 18 November 2026
  • setsebool(8) — SELinux userspace project via man7.org, page obtained 4 August 2026, accessed 18 November 2026
  • semanage-port(8) — SELinux userspace project via man7.org, page obtained 4 August 2026, accessed 18 November 2026
  • getsebool(8) — SELinux userspace project via man7.org, page obtained 4 August 2026, accessed 18 November 2026
  • ausearch(8) — Linux audit project via man7.org, page obtained 3 August 2026, accessed 18 November 2026
  • semanage-permissive(8) — SELinux userspace project via man7.org, page obtained 4 August 2026, accessed 18 November 2026
  • audit2allow(1) and audit2why(1) — Debian manpages, bookworm, policycoreutils-python-utils 3.4-1, page shows "October 2010" and "Source last updated: 2022-06-05", accessed 18 November 2026
  • apache.te, SELinux Reference Policy — SELinux Project, main branch, no date shown, accessed 18 November 2026
  • SELinux Notebook: object classes and permissions — SELinux Project, no date shown, accessed 18 November 2026