Setup https on nginx

I’ve tried following three or four tutorials, but I still can’t get my site to load with https. I bought a ssl certificate from namecheap and they gave me three files when I generated the ssl. A Key, A Certificate and the csr. I have saved each in /root/ /root/ /root/

Following along the tutorial found at I have rebuilt my /etc/nginx/sites-available/ file to be this:

#Redirect from 80
server {
    listen 80;
    rewrite ^/(.*)$1 permanent;

server {
  listen 443 ssl;
  ssl_certificate /root/;
  ssl_certificate_key /root/;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  root /var/www/html;
  index index.html;
  default_type "text/html";

  location / {
    try_files $uri $uri/ /index.html;

#redirect for api's to node server.
  location /api {
    # Serve api requests here. This will connect to your node
    # process that is running on port 3001.
    proxy_pass http://localhost:3001;
    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;

Before I tried to get this running on ssl everything was running fine. When I run sudo service nginx restart. Currently it restarts just fine. 

I have changed /etc/nginx/sites-available/default to

server {
 listen 443 ssl default_server;
 root /var/www/html;
 index index.html index.htm index.nginx-debian.html;
 server_name _;
 location / {
   try_files $uri $uri/ =404;

Any thoughts?

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there @gabrielsuttner,

The configuration file looks correct, what happens when you try to visit your domain via https? Are you getting any errors?

Also what happens when you run an Nginx config test:

  1. sudo nginx -t

I would also recommend checking your Nginx error log as well:

  1. sudo tail -100 /var/log/nginx/error.log

Another thing that I could suggest is taking a look at this Nginx Config tool here which would help you to generate a correct Nginx configuration file:

Regards, Bobby