NGINX is a powerful and versatile web server that is widely used to serve static content, reverse proxy, and load balance across servers. Whether you're a beginner or an experienced user, having a cheatsheet handy can save time and help you navigate NGINX configurations efficiently. Let's dive into a quick reference guide for NGINX.
Installation and Basic Commands
Installation
sudoapt-get updatesudoapt-getinstallnginx
Start/Stop/Restart NGINX
sudoservice nginx startsudoservice nginx stopsudoservice nginx restart
Check NGINX Configuration
nginx-t
Configuration File Locations
- Main configuration file:
/etc/nginx/nginx.conf
- Server block configuration:
/etc/nginx/sites-available/
- Enabled server block symlink:
/etc/nginx/sites-enabled/
Server Blocks
Basic Server Block Structure
server{listen80;server_nameexample.comwww.example.com;location/{# Configuration for handling requests}}
Redirect HTTP to HTTPS
server{listen80;server_nameexample.comwww.example.com;return301https://$host$request_uri;}
Locations and Directives
Root Directive
location/{root/path/to/your/files;indexindex.html;}
Proxy Pass
location/app{proxy_passhttp://backend_server;proxy_set_headerHost$host;proxy_set_headerX-Real-IP$remote_addr;}
URL Rewriting
location/blog{rewrite^/blog/(.*)$/$1break;}
SSL Configuration
SSL Certificate
ssl_certificate/path/to/your/certificate.crt;ssl_certificate_key/path/to/your/private.key;
Enable SSL
server{listen443ssl;server_nameexample.com;# SSL configuration here}
SSL Redirect
server{listen80;server_nameexample.com;return301https://$host$request_uri;}
Load Balancing
Round Robin Load Balancing
upstreambackend{serverbackend1.example.com;serverbackend2.example.com;}server{location/{proxy_passhttp://backend;}}
This cheatsheet covers essential NGINX configurations, but remember to consult the official documentation for more in-depth details. NGINX's flexibility allows it to be used in various scenarios, making it a crucial tool for web server management.
Top comments(1)

- LocationKarachi, Pakistan
- EducationLittle Folk's School
- WorkFreelance Full Stack Web Developer
- Joined
Thanks! Saved it
For further actions, you may consider blocking this person and/orreporting abuse