NGINX

Config

Config - NGINX

Annotated config

server {
    listen 80;
    server_name crystallover.com.au www.crystallover.com.au;  # Will match request 'Host' header
    root /var/www/html;   # Where the website files are hosted, beware of file permissions for the user running NGINX server
 
    index index.php index.html index.htm;
 
    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
 
    client_max_body_size 500M;
 
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
 
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
 
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }
 
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
 
    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm.sock; # PHP FPM socket
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

Config - PHP FPM

Cheatsheet

Test config

nginx -t

Reload config

nginx -s reload

Analyse logs

Dynamic modules

  • Dynamic modules are loaded using the load_modules directive.

    The RPM package for each module has a .conf file in the /usr/share/nginx/modules directory. The .conf file contains a single load_modules directive.

    This means that whenever a new dynamic module is installed, it will automatically be enabled and NGINX will be reloaded.

  • Prevent dynamic modules from being enabled automatically

    You may want to avoid dynamic modules being enabled automatically. Simply remove this line from the top of /etc/nginx/nginx.conf:

    include /usr/share/nginx/modules/*.conf;

Tools

Resources