Install and setup ( Ubuntu 20.04 )
1. sudo apt update
2. sudo apt install nginx
3. Enable firewall with sudo ufw enable
4. List firewall apps with sudo ufw app list
Special note:
When you enable the firewall in the previous step, you won't be able to SSH to your server
unless you allow OpenSSH with sudo ufw allow OpenSSH
5. Check firewall status: sudo ufw status
6. Allow NGINX in the firewall with:
sudo ufw allow 'Nginx Full' or
sudo ufw allow 'Nginx HTTPS' or
sudo ufw allow 'Nginx HTTP'
7. Check status again sudo ufw status
8. Test that webserver is running by visiting your server's IP
9. If it isn't running then try starting it with sudo systemctl start nginx
Default 443 block SSL reverse proxy
server {
server_name your_domain.com;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/staging.timetrack.slgotting.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/staging.timetrack.slgotting.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5003;
}
}
Example final nginx conf file
server {
server_name example.com www.example.com;
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5007;
}
}
server {
server_name staging.example.com;
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:5006;
}
}
server {
listen 80;
listen [::]:80;
if ($host = example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = www.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name example.com www.example.com ;
return 404; # managed by Certbot
}