brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: nginx proxy_hide_header strips backend headers like X-Powered-By

Nginx
~/tips/tip-nginx-proxy-hide-header

proxy_hide_header X-Powered-By;

Removes headers that reveal backend software versions before responses reach the client.

Apps behind nginx often announce themselves: X-Powered-By: PHP/8.1, X-AspNet-Version, or a framework name. Hiding the nginx version does little if the backend shouts its own.

location / {
    proxy_pass http://127.0.0.1:8081;
    proxy_hide_header X-Powered-By;
    proxy_hide_header X-AspNet-Version;
}

Each line removes one header from the backend’s response before nginx passes it on. If the backend sends X-Powered-By and a Server-Timing header, only Server-Timing is left after the change. It works for any header name, so it is also how you drop debug headers an app adds in production.

nginx already hides a few by default, such as Date, Server and the X-Accel- headers. The opposite directive, proxy_pass_header, lets one of those through again.

Same trap as with add_header: the directive is inherited from the level above only when the current level has none of its own. Put one proxy_hide_header in a location and the ones from the server block stop applying there. So X-Powered-By shows up again in that location. I’d keep them all in a small snippet file and include it wherever you proxy. And hiding a version number is a small step. It slows down lazy scanners, but you still need to update the software behind it.

Further reading: proxy_hide_header

Going deeper: Guide: fix a 502 Bad Gateway in Nginx Proxy Manager, with a checklist that finds the cause

More Nginx tips sudo certbot --nginx -d example.com -d www.example.com /data/nginx/custom/server_redirect.conf map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; All Nginx tips (50) All topics

Link