Use "include" in nginx server block but where to save?
You can put the file wherever you want.
If you use a relative path, however, then it will be relative to the nginx configuration directory (e.g. /etc/nginx
on Linux, /usr/local/etc/nginx
on BSD, etc.).
I personally create a directory /etc/nginx/includes
and place these configuration bits in there. For example:
server {
server_name deploy.example.com;
include includes/listen-80;
include includes/letsencrypt;
return 301 https://$host$request_uri;
}
Where /etc/nginx/incldues/listen-80
contains:
listen 80;
listen [::]:80;
And /etc/nginx/includes/letsencrypt
contains:
location /.well-known/acme-challenge/ {
root /var/www;
try_files $uri =404;
}
Of course I have many other such configuration bits.
@michaelhampton answered the question that, at first read, I thought you had asked, too. As his example shows, you can use the include
directive in a server
block. You can actually use it in any block, so using it in the server block is fine, too.