TECH / Серверы и сайты 3 min read

How to Remove the X-Powered-By Header in PHP, Nginx, Apache, and Express

NEMCD Author
Published Mar 4, 2013 · 3 min

By default, PHP and many web frameworks attach an X-Powered-By HTTP response header to every page, broadcasting your exact engine version (such as PHP/8.3.12). Automated vulnerability scanners love that header because it tells them immediately which version-specific exploits to throw at your server.

Hiding X-Powered-By HTTP response headers on a web server

Stripping X-Powered-By takes less than a minute. Below are the clean fixes for PHP, Nginx, Apache, and Node.js (Express), plus a quick command to verify the change live.

1. In php.ini (Best Fix for PHP)

Open your active php.ini file (find its exact path with php --ini or phpinfo()) and set expose_php to Off:

expose_php = Off

Reload PHP-FPM or Apache so the change takes effect:

# For PHP-FPM (adjust version as needed)
systemctl reload php8.3-fpm

# For mod_php on Apache
apache2ctl graceful

Disabling it in php.ini stops PHP from generating the header at the source across every site on the server.

2. In Nginx (Reverse Proxy or Shared PHP)

To strip the header at the Nginx layer – and hide Nginx’s own version number at the same time – add these lines inside your http, server, or location block:

server_tokens off;
fastcgi_hide_header X-Powered-By;
proxy_hide_header X-Powered-By;

Test your configuration and reload gracefully: nginx -t && systemctl reload nginx.

3. In Apache (.htaccess on Shared Hosting)

If you do not have root access to php.ini, drop the following snippet into your site’s .htaccess file (requires mod_headers):

<IfModule mod_headers.c>
    Header unset X-Powered-By
    Header always unset X-Powered-By
</IfModule>

On a self-managed Apache server, also set ServerTokens Prod and ServerSignature Off in the main server config so Apache stops advertising OS and module versions on error pages.

4. In Node.js (Express) and Verifying with curl

Express.js sends X-Powered-By: Express by default as well. Turn it off with one line right after creating your app instance:

app.disable('x-powered-by');

Verify the live response headers from any terminal using curl (after clearing any Nginx or Cloudflare cache):

curl -I https://example.com

Hiding server banners does not replace keeping PHP and your CMS patched, of course, but removing noisy version headers cuts down automated reconnaissance and keeps your HTTP footprint clean.

Related posts:

Leave a Comment