We use a modular approach here, with most configuration settings outsourced to individual files.
- Main Configuration File
- Global HTTP Settings
- Server Default Settings
- Extra Settings
- Virtual Web Servers
- Content Security Policies
On line 47 in the above
/etc/nginx/nginx.conf various options from the
/etc/nginx/conf.d are included.
They are discussed in Global HTTP Settings.
Nginx can host multiple websites on a single installation. In Nginx a website is called a “server”. (Apache HTTPd calls them “virtual hosts”). Servers are identified by their hostname and or IP address.
Sticking to our modular approach, we define individual servers in the directory
So to activate or disable servers, symbolic links are created or deleted in
/etc/nginx/servers-enabled, pointing to server definitions in
To activate a server:
$ sudo ln -s /etc/nginx/servers-available/example.net.conf \ /etc/nginx/servers-enabled/ $ sudo service nginx reload
$ sudo rm /etc/nginx/servers-enabled/example.net.conf $ sudo service nginx reload
Configuration of individual sites depends heavily on the nature of the website.
As reference we show a simple website who serves static HTML pages in Virtual Web Servers.
Test and Activate¶
The configuration is always tested for errors before the Nginx service starts. Alternatively a test can be requested manually:
$ sudo service nginx configtest nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful