Modify the Nginx configuration to act as a reverse proxy. Edit the Nginx site configuration file:
sudo vi /etc/nginx/sites-available/default
Update the following server block at the bottom (replace [yourDomain.com] and adjust the [YOUR_APP_PORT] to match your application):
server {
listen 443 ssl;
# listen [::]:80;
server_name [yourDomain.com];
ssl_certificate /etc/letsencrypt/live/[yourDomain.com]/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/[yourDomain.com]/privkey.pem;
# root /var/www/example.com;
# index index.html;
location / {
# try_files $uri $uri/ =404;
proxy_pass http://localhost:[YOUR_APP_PORT];
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
restart it to apply your changes:
sudo systemctl restart nginx
You should be able to access your web application over HTTPS by visiting https://[yourDomain.com]