Nginx Related Tips and Configurations

This page contains all the information you'll ever need regarding nginx and how to work with it in both a production and development/static enviroment.

Noteable Nginx Points

For nginx, On most systems, The config can be found in /etc/nginx & virtual hosts are present in:

  • /etc/nginx/conf.d - CentOS/RHEL/AlmaLinux/RockyLinux Based systems
  • /etc/nginx/sites-available - Debian/Ubuntu Based systems

Things to know:

  • File names must end in a .conf as by default, the nginx.conf (the parent file) only sees .conf files (*.conf - setting).
  • Files placed inside sites-available must be system linked using ln command to sites-enabled as by default, the nginx.conf (the parent file) only sees the .conf files present inside siltes-enabled and not sites-available.

Basic Nginx Config

This is the most basic nginx config where proxy_pass & server_name values need to be modified and it should work in most applications. This config already passes the real IP in the proxy_set_header value and it can be commented out by putting a # in the beginning of the line to disable.

server {
    listen 80;
    server_name www.example.com example.com;

    location / {

        proxy_pass http://localhost:2000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

}
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9