On an Apache Server (2.4.37) running on CentOS 8, there should be a redirection of HTTP traffic on port 8765 to the default https port. Therefore, I am trying to make the server listen to port 8765 in order to set up a virtual host which listens to this port. But it fails already here.

When I just add the line Listen 8765 to line 4 of a conf file in /etc/httpd/conf.d/ and restart apache, there is the following error:

AH00526: Syntax error on line 4 of /etc/httpd/conf.d/redirect-8765.conf:
Systemd socket activation is used, but this port is not configured in systemd

(Contrary to the error message, this is arguably not a syntax error, as the problem lies with the systemd port configuration.)

Looking into the manpage of httpd.socket(8), I have found the following instructions:

The httpd listener configuration must exactly match the ListenStream options configured for the httpd.socket unit. [...] If additional Listen directives are added to the httpd configuration, corresponding ListenStream options should be added via drop-in files, for example via systemctl edit httpd.socket.

There was a drop-in file for ssl (called 10-listen443.conf) at the location /usr/lib/systemd/system/httpd.socket.d/, where I wrote another file called 20-redir8765.conf with the following contents:


This did not solve anything, so I tried to execute, as per the manpage, systemctl edit httpd.socket, which edited the file /etc/systemd/system/httpd.socket.d/override.conf. There, I have inserted the same lines as above. This also lead to the same error message, but removing the Listen directive from the httpd configuration file (not the systemd socket config), and restarting the server, the server status indicated the following:

httpd.socket - Apache httpd Server Socket
 Loaded: loaded (/usr/lib/systemd/system/httpd.socket; enabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/httpd.socket.d
         └─10-listen443.conf, 20-redir8765.conf
 Active: active (running) since Fri 2020-09-11 14:18:09 UTC; 2h 2min ago
   Docs: man:httpd.socket(8)
 Listen: [::]:80 (Stream)
         [::]:443 (Stream)
         [::]:8765 (Stream)
         [::]:8765 (Stream)
 CGroup: /system.slice/httpd.socket

Assuming that now the ports are activated via systemd, I re-inserted the Listen directive. But then, the same initial error arised.

Under these circumstances, how can I add a VirtualHost which listens to a port?

EDIT: There's different information displayed in systemctl status httpd.socket vs. systemctl status httpd, which I have previously overlooked. Removing override.conf, inserting the Listen 8765 directive, stopping httpd.service as well as httpd.socket, and finally starting httpd.socket before httpd.service made everything work - for the moment. To see if the settings survive a reboot, the machine was rebooted, but now the SSH connection times out and pings fail.

  • 1
    You have port 8765 listed twice? – Michael Hampton Sep 11 at 17:45
  • @MichaelHampton Yes, I have had listed it twice. Maybe once from 20-redir8765.conf and once from override.conf? – user2009388 Sep 11 at 23:06
  • That seems like it might be a problem. – Michael Hampton Sep 11 at 23:22

It should be noted that there is a substantial difference when querying the status of httpd.service and httpd.socket, the latter of which was called unintentionally. I have overlooked that previously, which made debugging more challenging.

The problem seems to have been an incorrect config reload. It would be possible to reboot the machine, but if you need it to be running, restarting httpd.socket might be enough on some machines. However, that did not work for me. What worked reliably were the following commands, in that order:

systemctl daemon-reload
systemctl stop httpd.socket
systemctl stop httpd.service
systemctl start httpd.socket
systemctl start httpd.service

To save the custom drop-in file from being overwritten by package updates, I have moved it from /usr/lib/systemd/system/httpd.socket.d/ to /etc/systemd/system/httpd.socket.d/.

The failed reboot from the update of OP was an unrelated RAID issue.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.