Basic NGINX setup

Prerequisites

Configuration

  1. Create new file /etc/nginx/sites-enabled/00-changeme.conf

     server {
         listen 80;
         server_name change.this.domain;
         return 301 https://$host$request_uri;
     }
    
     server {
         server_name change.this.domain;
         location / {
             proxy_pass http://127.0.0.1:20000; # change port if you are running on different than default port
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection 'upgrade';
             proxy_set_header Host $host;
             proxy_cache_bypass $http_upgrade;
         }
         listen 443 ssl;                     
     }
    

    Don’t forget to change changeme in filename and change.this.domain to domain you are using e.g. mybotishere.sogebot.xyz

  2. Run certbot (output may vary by your configuration) and select which domain should have HTTPS enabled. We are selecting 1 for domain and we already set redirect to HTTPS, so we don’t want any further changes 1

     $ certbot
    
     Which names would you like to activate HTTPS for?
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     1: change.this.domain
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     Select the appropriate numbers separated by commas and/or spaces, or leave input
     blank to select all options shown (Enter 'c' to cancel): 1
    
     Obtaining a new certificate
     Performing the following challenges:
     http-01 challenge for change.this.domain
     Waiting for verification...
     Cleaning up challenges
     Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/00-changeme.conf
     
     Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     1: No redirect - Make no further changes to the webserver configuration.
     2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
     new sites, or if you're confident your site works on HTTPS. You can undo this
     change by editing your web server's configuration.
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     Congratulations! You have successfully enabled https://change.this.domain
     
     You should test your configuration at:
     https://www.ssllabs.com/ssltest/analyze.html?d=change.this.domain
     - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     
     IMPORTANT NOTES:
      - Congratulations! Your certificate and chain have been saved at:
        /etc/letsencrypt/live/change.this.domain/fullchain.pem
        Your key file has been saved at:
        /etc/letsencrypt/live/change.this.domain/privkey.pem
        Your cert will expire on 2020-09-30. To obtain a new or tweaked
        version of this certificate in the future, simply run certbot again
        with the "certonly" option. To non-interactively renew *all* of
        your certificates, run "certbot renew"
      - If you like Certbot, please consider supporting our work by:
     
        Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
        Donating to EFF:                    https://eff.org/donate-le
    
  3. Check if NGiNX configuration is OK

      $ nginx -t
      nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
      nginx: configuration file /etc/nginx/nginx.conf test is successful
    
  4. Restart NGiNX and enjoy your bot on https://change.this.domain

     $ systemctl restart nginx # systemd
     # OR
     $ service nginx restart   # sysv init
    

Useful links

1 Like