Score:0

Apache can’t connect to Unix domain socket

cn flag

I am trying to install a custom web application with Apache HTTPd as frontend web server. But why does Apache report it couldn't access the Unix socket where the application listens?

The web application is configured to listen here:

# ls -l /run/mt_plackup_master.sock
srwxrwxrwx. 1 apache apache 0 Jan 18 21:16 /run/mt_plackup_master.sock

I manually made chown apache:apache and chmod 777 to grant all possible permissions on the socket file.

The apache user is able to access the file:

# su apache -s /bin/sh -c "curl --unix-socket /run/mt_plackup_master.sock --head localhost"
HTTP/1.1 301 Moved Permanently
Location: some_sub_page/
Date: Tue, 18 Jan 2022 20:21:56 GMT
Connection: keep-alive

But Apache serves a HTTP 503 Service unavailable and writes to the error log:

[Tue Jan 18 21:16:32.738727 2022] [proxy:error] [pid 864514:tid 139775709259520] (13)Permission denied: AH02454: HTTP: attempt to connect to Unix domain socket /run/mt_plackup_master.sock (localhost) failed
[Tue Jan 18 21:16:32.738781 2022] [proxy_http:error] [pid 864514:tid 139775709259520] [client ::1:50532] AH01114: HTTP: failed to make connection to backend: httpd-UDS

This is with Apache 2.4.37 on Rocky Linux.

Update: as requested

# ls -Z /run/mt_plackup_master.sock 
system_u:object_r:var_run_t:s0 /run/mt_plackup_master.sock
in flag
Most probably selinux. Run `ls -Z` on the socket and share the output.
djdomi avatar
za flag
and what is the user that runs apache? usually for debian is www-data
Daniel Böhmer avatar
cn flag
On Rocky Linux the user is named `apache` as mentioned
Score:0
cn flag

I tried

# chcon -t httpd_sys_rw_content_t /run/mt_plackup_master.sock

and it seems to work. Is that the right SELinux context for a web application socket? Any recommendations?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.