0

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...

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.