Config
Config - NGINX
-
/etc/nginx/nginx.conf
includes all conf files in/etc/nginx/conf.d/*.conf
-
Each line must end with a semicolon
;
-
GitHub - digitalocean/nginxconfig.io (opens in a new tab)
NGINX configuration generator on steroids
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 singleload_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
-
GitHub - allinurl/goaccess (opens in a new tab)
GoAccess - Visual Web Log Analyzer (opens in a new tab)
Analysing nginx logs using GoAccess (opens in a new tab)
GoAccess
is an open source real-time web log analyzer and interactive viewer that runs in a terminal on *nix systems or through your browser. -
GitHub - trimstray/nginx-admins-handbook (opens in a new tab)