Question

Setup SSL on NGINX

Hi Expert, I had gone through this guide: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-20-04 and successfully setup the http server. But i have 2 questions.

  1. Can i have 2 listeners: port 80 and 443 in the same file ( /etc/nginx/sites-available/your_domain)

  2. I got my domain and SSL from Namecheap. I had update the NS and the traffic has redirected to DigitalOcean (correct way). But is there anyway to get the SSL from Namecheap and insert into the NGINX server?

Thanks!


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
October 2, 2022

Hi there,

Yes, it is possible to have two Nginx server blocks, one for port 80 and one for port 443 for the same domain name.

In the SSL Nginx server block, you need to make sure that you have the following details:

 listen 443;

 server_name your_domain.com www.your_domain.com;

 ssl on;
 ssl_certificate /etc/nginx/ssl/yourdomain-bundle.crt;
 ssl_certificate_key /etc/nginx/ssl/yourdomain.key;
    
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

Then make sure that you’ve added your SSL private key and the certificate bundle to those files specified din the config accordingly.

Before restarting Nginx, make sure to run a config test with: nginx -t and if you get Syntax OK then proceed and restart the Nginx service.

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.

© 2023 DigitalOcean, LLC.