Skip to content

Instantly share code, notes, and snippets.

@nurmdrafi
Created April 22, 2024 11:08
Show Gist options
  • Save nurmdrafi/73f6470f3bddd03f5189d70d1568f3f7 to your computer and use it in GitHub Desktop.
Save nurmdrafi/73f6470f3bddd03f5189d70d1568f3f7 to your computer and use it in GitHub Desktop.
Basic NGINX Config

Create File

sudo nano /etc/nginx/sites-available/test

Basic Config

If project running on server using docker or pm2
server {
    listen 80;
    listen [::]:80;
    server_name test.com;
    # server_name _; (if has no domain)
    
    access_log /var/log/nginx/reverse-access.log;
    error_log /var/log/nginx/reverse-error.log;

    location / {
        proxy_pass http://localhost:3050;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
If using index.html or react.js not running on server
server {
    listen 80;
    listen [::]:80;
    server_name test.com;
    
    root /var/www/html/test/;
	index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Test Configuration

sudo nginx -t

Symlink

sudo ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/

Install the SSL certificate

sudo certbot --nginx -d test.com

Reload Nginx to apply changes

sudo systemctl reload nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment