Skip to content

Instantly share code, notes, and snippets.

@eitozx
Created June 5, 2024 01:40
Show Gist options
  • Save eitozx/01511d5ac560f00dccb26e57bfe2440a to your computer and use it in GitHub Desktop.
Save eitozx/01511d5ac560f00dccb26e57bfe2440a to your computer and use it in GitHub Desktop.
sudo apt update
sudo apt install nginx
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
nano /etc/nginx/sites-available/example.com
server {
    server_name example.com www.example.com;

    location / {
        proxy_pass http://127.0.0.1:8000;  # Replace with your application server address
        include /etc/nginx/proxy_params;  # You can create this file for proxy settings
    }

    listen 443 ssl; # 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
}

server {
    if ($host = www.example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name example.com www.example.com;
    return 404; # managed by Certbot
}
/etc/nginx/sites-enabled/example.com 
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment