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: server_redirect.conf adds nginx lines to every redirection host in Nginx Proxy Manager

Nginx
~/tips/tip-nginxproxymanager-server-redirect-conf

/data/nginx/custom/server_redirect.conf

A custom file that Nginx Proxy Manager includes at the end of every redirection server block.

Nginx Proxy Manager has several custom config files, and I tend to remember only the one for proxy hosts. The redirection hosts have their own file, which is handy when you want a setting on those and not on your apps.

/data/nginx/custom/server_redirect.conf

Per the Nginx Proxy Manager docs, every file in that folder is optional, and server_redirect.conf is included at the end of every redirection server block. Its neighbours are server_proxy.conf for proxy hosts, server_dead.conf for 404 hosts, and server_stream.conf for streams.

As an example, this adds a header to every redirect, which you can see with curl -I:

add_header X-Served-By "npm-redirect";

The nginx docs say add_header works without always for response codes 200, 201, 204, 206, 301, 302, 303, 304, 307 and 308, so a normal redirect gets the header.

The caveat is nginx’s inheritance rule for add_header: directives are inherited from the previous level only if the current level defines none. A location block that already has its own add_header will not get the one from the server level. Since the file is part of every redirection host, a typo affects all of them, so keep it short.

Further reading: Nginx Proxy Manager advanced configuration, nginx headers module

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 map $http_upgrade $connection_upgrade { proxy_intercept_errors on; proxy_redirect http://localhost:3000/ /app/; sub_filter 'http://127.0.0.1:8081/' 'https://example.com/app/'; All Nginx tips (50) All topics

Link