Nginx Configuration

Well configuring nginx is essential to get the the best out of your server.

As you may have diffent use cases for your server I suggest you to edit the configuration according your needs. I have divided the configuration in two main examples: with and without the use of ssl module. I decided to include Naxsi in the configuration as I think it is essential for securing your server especially if you want to implement the use of php or sql in your website.

The general configurations files are located at /etc/nginx/nginx.conf while the server configurations will be at /etc/nginx/some_folder/default.conf. The best practice is to keep these two folders separated, however for simplicity you may prefere to merge them in one only file in case you're just hosting a simple website. The configuration consist of:

  • Directives
  • Blocks
  • Context
  • Thanks to include some_file you can add another file inside the nginx.conf configuration file. With a server block you can create any virtual server you may need. Finally, locations represents the configuration of a particular location of a specific server. The configuration scheme is as follows:

    TIP: The log files can be found at /var/log/nginx. When you modify your settings you need to use the command nginx -s reload. If you need more data than the one provided I suggest you to read the nginx docs.

    HTTPS and PHP-FPM

    This configuration is mean for who want to implement ssl in nginx. This configuration ensures that the data will be encrypted by internally redirect port 80 traffic (plain http) to 443 (encrypted https).

    nginx.conf

    /available/default.conf

    HTTP and PHP-FPM

    This configuration is meaned for who doesn't need to use the ssl module. For example you host a website where there is no use of logins or personal data to protect.

    nginx.conf

    /available/default.conf

    This article was last updatated the 3/1/16