FREE SSL ON NGINX WEBSITE WITH PORT PROXY PASS


Requirements


  1. A domain. Like -example.com
  2. You can acquire a site name on Namecheap, Godaddy, etc
  3. On the domain server, add A record with example.com pointing to your server’s public IP address.
  4. Install Nginx, in server-
  5. Most important - your website working with example.com not example.com:8080

Step 1 — Installing Certbot

For using Let’s Encrypt to get an SSL certificate is to put in the Certbot software on your server.

# sudo add-apt-repository ppa:certbot/certbot
# sudo apt-get update
# sudo apt-get install python-certbot-nginx

Certbot is now set to use.

Step 2 — Setting up Nginx Config

On server-
Go to
# cd /etc/nginx/sites-available/
# ll
Setting up Nginx Config


Copy a default and past the same along with your domain name.
# cp -r default example.com

Setting up Nginx Config 2


# vim example.com
Delete all the things and add the following line and save this file For Edit press i (i for insert mode)
To save the file (press Esc then:wq! then enter) It'll save files. If you do not want to keep the file then (press Esc then:q! Then enter).

server {

       server_name example.com;

       root /var/www/html/;


       location / {
              access_log off;
                proxy_pass http://127.0.0.1:8080;

                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header Host $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       }
}


 Setting up Nginx Config 3


Then, verify the syntax of your configuration edits

# sudo nginx -t

If you get any errors, reopen the file and check for typos, then test it again. 
Once you notice your configuration’s syntax is correct, refresh Nginx to get the new configuration.

# sudo systemctl reload nginx
Or
# sudo /etc/intd.d/nginx restart

If you have got the ufw firewall enabled, as recommended by the prerequisite guides, you should adjust the settings to permit for HTTPS traffic. You likewise can off your ufw.
# sudo ufw status

Step 4 — Installation an SSL Certificate

# sudo certbot --nginx -d example.com

This runs certbot with the --nginx plugin, using -d to specify the names we’d just like the certificate to be valid for.  If this is your prime time running certbot, you will be prompted to enter an email address and agree to the terms of service. After doing so, certbot will communicate with the Let’s Encrypt server, then run a challenge to verify that you just control the domain you’re requesting a certificate.
If that’s successful, certbot will ask how you’d wish to configure your HTTPS settings.
Installation an SSL Certificate

Select your choice then hit ENTER. The configuration is going to be updated, and Nginx will reload to select the new settings. certbot will be done up with a message telling you the command was successful and where your certificates are stored:
Installation an SSL Certificate 2

Your certificates are downloaded, installed, and loaded. Try reloading your website using https:// and see your browser’s security indicator. It should indicate that the domain is properly secured.

Step 5 — Certbot Auto-Renewal

Encrypt’s certificates are only legitimate for ninety days. This often encourages users to automate their certificate renewal process.

# sudo certbot renew --dry-run

If you detect no error, you’re all set.

Previous
Next Post »