Ravindra BagaleCourses & study guides Track your progress

Guides

Secure Nginx Config: Hide Server Version and Powered-By Headers

To hide the Nginx version, set server_tokens off; in nginx.conf, test with nginx -t, and reload. Remove X-Powered-By in PHP (expose_php = Off) or with an Nginx header directive. Fingerprinting still happens, but you stop giving free version numbers.

Quick answer

sudo sed -n "1,80p" /etc/nginx/nginx.conf | head
# inside http { } block:
#   server_tokens off;
sudo nginx -t && sudo systemctl reload nginx
curl -I https://YOUR_SITE

Why hide version headers?

Tools like WhatWeb read Server and X-Powered-By. A clear nginx/1.18.0 or PHP/7.4 speeds up exploit searches. You cannot hide everything, but you can stop handing out the version for free.

What are you changing?

server_tokens controls whether Nginx prints its version. PHP expose_php controls X-Powered-By. Both are small config edits on your server.

How do I do it step by step?

  1. On your EC2 or VPS, open the main config:
    sudo nano /etc/nginx/nginx.conf

    What it means: Amazon Linux and Ubuntu both use this file as the main entry.

  2. Inside the http { } block add:
    http {
        server_tokens off;
        # ... existing lines
    }
  3. Test and reload:
    sudo nginx -t && sudo systemctl reload nginx
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    What it means: Syntax is good and Nginx reloaded without dropping the whole server.

  4. For PHP-FPM, set in the active php.ini:
    expose_php = Off
    # then: sudo systemctl reload php-fpm   # name may be php8.2-fpm

    What it means: PHP stops sending X-Powered-By on responses.

  5. Verify from your laptop:
    curl -I https://YOUR_SITE
    HTTP/2 200
    server: nginx
    # no nginx/1.x and no x-powered-by

    What it means: Server no longer advertises a version string. Good.

Next, add security headers (see the curl guide) and work through the website security checklist.

Ravindra Bagale's Tip

Hiding banners is layer one, not a magic shield. Still patch. Still use TLS. Kabir in Jaipur hid Server: nginx/1.25 and slept better — then he also turned on automatic security updates.

Quick quiz: check what you learned

  1. Which nginx setting hides the version number in the Server header?

    1. server_tokens off;
    2. autoindex on; in a server
    3. sendfile off; in http block
    4. gzip on; for compression
    Show answer

    A. server_tokens off; removes the version from Server and error pages.

  2. After editing nginx.conf, what must you do?

    1. Test config then reload nginx
    2. Delete the access log file
    3. Disable SELinux forever
    4. Open port 21 for FTP
    Show answer

    A. nginx -t then systemctl reload nginx.

Learn it properly

This guide is the short path. These pages go deeper, with labs:

Frequently asked questions

What does server_tokens off do?

Nginx stops adding its version number to the Server header and error pages.

Will this stop WhatWeb completely?

No. It only removes easy version leaks. Other clues remain.

How do I remove X-Powered-By?

For PHP set expose_php=Off. Or add more_clear_headers / proxy_hide_header where supported.

Is changing headers enough hardening?

No. Pair with TLS, least open ports, patches and a checklist.

Where is the deeper course lesson?

Cyber 32.5 Web server hardening and 36.3 WhatWeb fingerprinting.