Search code examples
nginxhttpsvirtual-machineoracle-cloud-infrastructure

How do I enable HTTPS on my Nginx server on Oracle cloud


So I am trying to setup https on my website, hosted on oracle cloud vm, running ubuntu. The website works fine without https, but I would rather it working with https. My domain name: rayyanshikoh.ga (got through freenom for learning and testing)

My configuration file:

server {
    listen 80;
    server_name 129.151.159.179 rayyanshikoh.ga www.rayyanshikoh.ga;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/ubuntu/personal-website/personal-website;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/rayyanshikoh.ga/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/rayyanshikoh.ga/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


}

I was following this tutorial: https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-20-04

But whenever I try to open my website using https on chrome, I get the error:

This site can’t be reachedwww.rayyanshikoh.ga took too long to respond.
Try:

Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_TIMED_OUT

Solution

  • I had the same issue and also I needed add to iptables ports 80, 443.

    sudo iptables -I INPUT -p tcp --dport 80 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
    sudo iptables -I INPUT -p tcp --dport 443 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
    sudo iptables -I OUTPUT -p tcp --sport 80 -m conntrack --ctstate ESTABLISHED -j ACCEPT
    sudo iptables -I OUTPUT -p tcp --sport 443 -m conntrack --ctstate ESTABLISHED -j ACCEPT