Skip to content
KYND Dev

Nginx Cheat Sheet

DevOps, Server1 min read

Monitoring access log

1tail -f /var/log/nginx/access.log

By default, the access log is located at /var/log/nginx/access.log. We can change the access log location at Nginx configuration file (at /etc/nginx/nginx.conf

1server {
2 access_log /path/to/file.log;
3
4 access_log on;
5}

Enable ssl certificate:

1server {
2 listen 443 ssl;
3 server_name www.app.example.com;
4 ssl_certificate {CERTIFICATE_PATH}; # example:/etc/nginx/app.example.com.crt
5 ssl_certificate_key {CERTIFICATE_KEY_PATH}; # example:/etc/nginx/app.example.com.key
6
7 #...
8}

Miscellaneous: Set max body size and gzip

1server {
2 gzip on; # Turn on, off gzip compression
3 client_max_body_size 100M; # Limit client body size to 100M
4}

Static assets

1server {
2 server_name static.example.com;
3 location / {
4 root /path/to/website;
5 }
6
7}

Redirect error pages

1error_page 404 /404.html;
2
3 location = /404.html {
4
5 root /usr/share/nginx/foo;
6
7 }
8
9
10
11 # redirect server error pages to the static page /50x.html
12
13 #
14
15 error_page 500 502 503 504 /50x.html;
16
17 location = /50x.html {
18
19 root /usr/share/nginx/foo;
20
21 }

Additional Reading:

NGINX Access Logs and Error Logs - JournalDev NGINX SSL Termination | NGINX Plus How To Configure Nginx to Use Custom Error Pages on Ubuntu 14.04 | DigitalOcean