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.conf
http{ 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 -t
Restart nginx service sudo systemctl restart nginx
or sudo service nginx restart
Check nginx status sudo systemctl status nginx
or sudo service nginx status
Issue 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.com
It’ll handle the required modification for https in nginx.conf
Automatically Renew Let’s Encrypt Certificates
crontab -e
0 12 * * * /usr/bin/certbot renew --quiet
Manually 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