Nginx Configuration Setup
Install Nginx
sudo apt update sudo apt install nginx
Link port with domain
Open this file in nano or vim
/etc/nginx/nginx.confhttp{ server{ listen 80; server_name DOAMIN.com www.DOMAIN.com; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://<IP_ADDRESS>; } } }
After updating nginx.conf apply these commandsTest nginx.conf
sudo nginx -tRestart nginx service sudo systemctl restart nginx or sudo service nginx restartCheck nginx status sudo systemctl status nginx or sudo service nginx statusIssue ssl certificate from certbot
Install certbot
sudo apt-get update sudo apt-get install certbot sudo apt-get install python-certbot-nginx
Obtain the SSL/TLS Certificate
sudo certbot --nginx -d example.com -d www.example.comIt’ll handle the required modification for https in nginx.conf
Automatically Renew Let’s Encrypt Certificates
crontab -e0 12 * * * /usr/bin/certbot renew --quietManually setup SSL and https configuration on nginx
http{ server{ listen 80; server_name spotcodes.in www.spotcodes.in; return 301 https://$server_name$request_uri; }
server { listen 443 ssl; server_name spotcodes.in www.spotcodes.in;
ssl_certificate /etc/letsencrypt/live/spotcodes.in/cert.pem; ssl_certificate_key /etc/letsencrypt/live/spotcodes.in/privkey.pem;
location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://3.83.202.107:2001; } } }
Test SSL certificate installation
Usefull links and credits
- https://www.nginx.com/blog/using-free-ssltls-certificates-from-lets-encrypt-with-nginx/#auto-renewal
Visit on Medium
