HTTP to HTTPS redirect is not working

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g., so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain

I ran this command: HTTP to HTTPS is not working.

It produced this output:server {
listen 80;
listen [::]:80;

listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/; # managed by Certbot
ssl_trusted_certificate /etc/letsencrypt/live/;

# Improve HTTPS performance with session resumption
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 5m;

# Enable server-side protection against BEAST attacks
ssl_prefer_server_ciphers on;

# Disable SSLv3
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

# Diffie-Hellman parameter for DHE ciphersuites
# $ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 4096
ssl_dhparam /etc/ssl/certs/dhparam.pem;

# Enable HSTS (
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";

# Enable OCSP stapling (
ssl_stapling on;
ssl_stapling_verify on;
resolver valid=300s;
resolver_timeout 5s;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html index.php;


My web server is (include version): nginx

The operating system my web server runs on is (include version): Ubuntu

My hosting provider, if applicable, is: Digital Ocean

Hi @facildeanotar

there is no redirect defined.

But a mixed definition (port 80 and port 443 in the same server block) is terrible.

First step: Split that in two definitions, one port 80, one port 443.

Then the nginx documentation has a lot of samples how to create a redirect http -> https.

thank you so much. it worked for me.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.