Setup NGINX with HTTPS
# Installation NGINX
sudo apt install nginx
Check if nginx web server run
curl localhost
or go to browser and access http://localhost
1. Creare configuration file in /etc/nginx/sites-available
nano /etc/nginx/sites-available/yourdomain.com
2. create a symbolic link to it in the /etc/nginx/sites-enabled/ directory.
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
3. Test the Nginx configuration for syntax errors:
sudo nginx -t
4. If the test is successful, restart Nginx to apply the changes:
sudo service nginx restart
Setup NGINX
location /<path>/ {
proxy_pass http://localhost:<port>/;
# Recommended headers to include
proxy_set_header Host $host; # Passes the original Host header
proxy_set_header X-Real-IP $remote_addr; # Passes the client IP address
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # Maintains a chain of client IPs
proxy_set_header X-Forwarded-Proto $scheme; # Indicates the original protocol (http/https)
}
Setting SSL with Let's Encrypt using Certbot
1. Install Certbot and the Nginx Plugin
sudo apt update
sudo apt install certbot python3-certbot-nginx
2. Obtain an SSL Certificate
sudo certbot --nginx -d yourdomain.com
3. Test the Nginx configuration for syntax errors:
sudo nginx -t
4. If the test is successful, restart Nginx to apply the changes:
sudo service nginx restart
5. Automatic Renewal
Certbot sets up a cron job or systemd timer to automatically renew your certificates before they expire
sudo certbot renew --dry-run