0

I have an Apache Server running on CentOS 8.2, whose sockets are managed by systemd socket activation. But I don't want it to listen on the default port 80, because I want to run a reverse proxy with Nginx at this port. Here's the current systemd socket configuration:

root@server6:~# systemctl status httpd.socket
● httpd.socket - Apache httpd Server Socket
   Loaded: loaded (/usr/lib/systemd/system/httpd.socket; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/httpd.socket.d
           └─20-redir8016.conf, 30-listen8017ssl.conf, override.conf
   Active: active (running) since Fri 2020-11-20 14:45:13 UTC; 1 weeks 0 days ago
     Docs: man:httpd.socket(8)
   Listen: [::]:80 (Stream)
           [::]:8001 (Stream)
           [::]:8002 (Stream)
           [::]:8003 (Stream)
    Tasks: 0 (limit: 820374)
   Memory: 0B
   CGroup: /system.slice/httpd.socket

As you can see, port 80 is enabled. This is by default. The other ports were added deliebrately. The manpage of httpd.socket(8) only describes how to add another port, not how to remove the default ones. Port 80 is not configured in any configuration file in /etc/httpd.

How can I deactivate port 80 here? Where is the default configuration stored?

1 Answer 1

3

You can list the files being used by systemd for the socket by using:

$ systemctl cat httpd.socket

and on my system this shows (some lines removed to keep it short):

# /usr/lib/systemd/system/httpd.socket
[Unit]
Description=Apache httpd Server Socket
[Socket]
ListenStream=80
[Install]
WantedBy=sockets.target

# /usr/lib/systemd/system/httpd.socket.d/10-listen443.conf
[Socket]
ListenStream=443

You can see that 2 named files are used (on my system) to listen on ports 80 and 443. You can use sudo systemctl edit httpd.socket to add more configuration. To actually cancel an existing configuration, you need to use the standard systemd method of entering an empty value for the keyword, i.e. in this case: ListenStream=, followed by any wanted additional values:

[Socket]
# cancel existing port 80 (and 443)
ListenStream=
ListenStream=8001
ListenStream=8002
ListenStream=8003

man systemd.syntax (or man systemd.unit in older versions) says

Various settings are allowed to be specified more than once, in which case the interpretation depends on the setting. Often, multiple settings form a list, and setting to an empty value "resets", which means that previous assignments are ignored.

3
  • Thanks, that was it! Really nicely explained. Even learned a helpful new command. I have now created a matching 00-resetports.conf in the drop-in directory. Follow-up question: Where in the docs does it say that entering an empty value for a keyword cancels existing configuration? I couldn't find it. Nov 30, 2020 at 16:32
  • 1
    I updated the answer: the info comes from man systemd.unit which includes .service .socket files, and many other types of unit.
    – meuh
    Nov 30, 2020 at 18:24
  • 1
    Again, thanks for the addendum. On my system however, that info is at systemd.syntax(7). Dec 1, 2020 at 11:21

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.