I have some nginx config snippets, which add locations, i.e. to send requests to a certain path to a fastcgi server.
For a clean deployment with ansible, I would like to use the /etc/nginx/conf.d
folder to add them there.
The problem is, location /something
belongs into a server block and the default server is already defined in /etc/nginx/sites-enabled/default
. And when I want to deploy more different locations, they should not need an own vhost for each include.
Possibly even a site in sites-enabled
would be useful, but it should still be composable. Different snippets can be included in the same config without knowing if other snippets are installed or not.
Is there a clean way to include location blocks from config snippets without modifying the default config?
The include statement in nginx works also for partial config, not just full servers. So you could create a directory e.g. /etc/nginx/default-site-locations/ and put there all your location_1.conf ... location_n.conf files.
Then, in your default configuration, include all conf files from that directory with
include /etc/nginx/default-site-locations/*.conf