Mobile app version of vmapp.org
Login or Join
Courtney195

: Nginx Php-Fpm Global Configuration So, ive got everything set with 6 wp websites sitting on my lemp stack. I have noticed that every single one of their nginx configurations are the same. Is

@Courtney195

Posted in: #Configuration #Linux #Nginx #Ubuntu

So, ive got everything set with 6 wp websites sitting on my lemp stack.

I have noticed that every single one of their nginx configurations are the same.

Is there a way I can globalize said configuration in nginx.conf?

For instance, caching sections, fastcgi, rewrites, etc...

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Courtney195

1 Comments

Sorted by latest first Latest Oldest Best

 

@Odierno851

Yes, this is easy enough and a real time saver as the number of sites you manage increases.

In the /etc/nginx/conf.d/ directory, create one or more '.conf' files with the reusable config snippets you need. For example, type sudo nano /etc/nginx/conf.d/headers.conf and put your headers in the file. The default nginx.conf has a wildcard include directive at the bottom which will automatically pick these up.

If you have snippets that should only be used on some sites, delete the wildcard include directive from nginx.conf and selectively place new ones in your server blocks, one snippet per directive.

Here are some examples:

server {
listen 80;
server_name example.com;

include /etc/nginx/conf.d/headers.conf;
include /etc/nginx/conf.d/caching.conf;

...
}

server {
listen 443;
server_name example.com;

include /etc/nginx/conf.d/headers.conf;
include /etc/nginx/conf.d/caching.conf;
include /etc/nginx/conf.d/https.conf;

...
}


Don't forget to test your new rules sudo nginx -t and then reload your config sudo service nginx reload to apply the changes.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme