Nginx Cheat Sheet
Table of Contents:
General Settings
Port (listen)
Domain name (server_name)
Access Logging (access_log)
Miscellaneous (gzip, client_max_body_size)
Serving Files
Static assets
The traditional web server.
Static assets with HTML5 History Mode
Useful for Single-Page Applications like Vue, React, Angular, etc.
Redirects
301 Permanent
Useful for handling www.yourdomain.com vs. yourdomain.com or redirecting http to https. In this case we will redirect www.yourdomain.com to yourdomain.com.
302 Temporary
Redirect on specific URL
Can be permanent (301) or temporary (302).
Reverse Proxy
Useful for Node.js applications like express.
Basic
Basic+
Upgraded Connection (Recommended for Node.js Applications)
Useful for Node.js applications with support for WebSockets like socket.io.
TLS/SSL (HTTPS)
Basic
The below configuration is only an example of what a TLS/SSL setup should look like. Please do not take these settings as the perfect secure solution for your applications. Please do research the proper settings that best fit with your Certificate Authority.
If you are looking for free SSL certificates, Let’s Encrypt is a free, automated, and open Certificate Authority. Also, here is a wonderful step-by-step guide from Digital Ocean on how to setup TLS/SSL on Ubuntu 16.04.
Large Scale Applications
Load Balancing
Useful for large applications running multiple instances.