Including Files In Nginx

Nginx has the include directive that can include the contents of a configuration file where it is run. This can be very useful for things like common fastcgi_pass directives or SSL configuration.

Extracting common configuration snippets into their own configuration allows you to, as an example, maintain your SSL ciphers and HSTS settings in a single place for all of the projects on the system.

As another example, you can upgrade all your PHP websites to the next version of PHP seamlessly. By updating a single file to point to the newer version and reloading nginx, you will not face any downtime during the upgrade and no projects were missed.

server {
  server_name * *;

  root   /var/www/;

  include ssl.conf;
  include php.conf;
  include general.conf;

  ssl_certificate /etc/letsencrypt/live/;
  ssl_certificate_key /etc/letsencrypt/live/;

Share this tip