Disable Apache Version

Disable Apache Version CentOS 6

For security reasons, it’s usually a good idea to disable the apache version of you public webserver, that way if there is a security issue with the version that’s running, it cannot be as easily verified, and exploited. This guide changes two Apache directives on CentOS 6, restarts httpd, and shows how to confirm the version is gone. The same directives work on RHEL, AlmaLinux and Rocky Linux 8, 9 and 10.

What Apache gives away by default

  • ServerSignature adds a footer line, such as Apache/2.2.15 (CentOS) Server at example.com Port 80, to pages Apache generates itself: error pages like 404 and 403, and directory listings.
  • ServerTokens controls the Server: HTTP response header sent with every response. On CentOS 6 the default config uses ServerTokens OS, which sends something like Server: Apache/2.2.15 (CentOS).

Hiding these does not fix any vulnerability. It only stops casual scanners from matching your exact version to a list of known bugs, so keep patching as normal (see Patching and Installing Updates on CentOS).

Prerequisites

  • Apache httpd installed and running (see Install Apache on CentOS 6.4).
  • Root access, or sudo rights to edit /etc/httpd/conf/httpd.conf and restart the service.

1. Log in and edit the Apache configuration

Login to your webserver, and su to root

Root shell prompt on web server zdedi after logging in and running su

edit the Apache Configuration

vi /etc/httpd/conf/httpd.conf
httpd.conf showing the default ServerSignature On line

2. Turn the signature off

find the line about server signature (in vi, type /ServerSignature and press Enter to jump to it)

ServerSignature On line found in httpd.conf before the change

change it to ServerSignature Off

ServerSignature Off
httpd.conf line changed to ServerSignature Off

3. Send only “Apache” in the Server header

find this line

ServerTokens OS
Default ServerTokens OS line in httpd.conf

change it as follows:

ServerTokens Prod
httpd.conf line changed to ServerTokens Prod

Prod is the shortest setting Apache supports, so the header becomes just Server: Apache. Removing the header completely is not possible with these directives alone. ServerTokens is a server-wide setting; it cannot be set per virtual host.

4. Test the config and restart Apache

Check the syntax first so a typo does not take the site down:

apachectl configtest

It should print Syntax OK. now restart apache

service httpd restart
service httpd restart output: Stopping httpd OK, Starting httpd OK

On systemd releases (CentOS 7, RHEL/AlmaLinux/Rocky 8-10) use systemctl restart httpd instead.

5. Verify

Request only the headers from the server:

curl -I http://localhost/

The Server: line should now read Server: Apache. Then browse to a page that does not exist; the 404 page should no longer show the version footer.

Troubleshooting

  • Version still shown: another file may set the directive again. Search the whole config with grep -Ri "ServerTokens\|ServerSignature" /etc/httpd/ and keep a single setting.
  • RHEL/AlmaLinux/Rocky 8-10: the stock httpd.conf may not contain these lines at all. Add them yourself, for example in /etc/httpd/conf.d/security.conf, then run the config test and restart.
  • PHP still reveals a version: PHP adds an X-Powered-By header. Set expose_php = Off in php.ini and restart httpd (or php-fpm).
  • Behind a proxy or load balancer: the Server header you see may come from the proxy, not Apache.

That’s it!

Hosted Linux Servers at www.zwiegnet.com/go

Related guides: Install Apache on CentOS 6.4 | Force Apache to Always Use HTTPS/SSL CentOS 6

Leave a Reply

Your email address will not be published. Required fields are marked *