1

I have a http website (with Flask and nginx) which is up and running. I'm trying to install ssl with certbot and following their steps leads to a successful installation message (congratulations...) but refreshing my webpage leads to 404 Not Found nginx/1.18.0 (Ubuntu). This is the nginx.conf file after sudo certbot --nginx

server {
    server_name www.mydomain.com;

    location /static {
        alias /home/ubuntu/adviser/flaskblog/static;
    }

    location / {
        proxy_pass http://localhost:8000;
        include /etc/nginx/proxy_params;
        proxy_redirect off;
    }

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

}
server {
    if ($host = www.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name www.mydomain.com;
    return 404; # managed by Certbot


}

any help is really appreciated.

2 Answers 2

5

First, just remove this line:

return 404; # managed by Certbot

which causes 404 error to be returned.

If it doesn't help, change whole this block:

server {
    if ($host = www.mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name www.mydomain.com;
    return 404; # managed by Certbot
}

to this:

server {
    listen 80;
    server_name www.mydomain.com;
    return 301 https://$host$request_uri;
}

UPDATE
Also, you can try to change

return 301 https://$host$request_uri;

to

return 301 https://www.yourdomain.com$request_uri;

(I had to replace mydomain with yourdomain due to some strange StackOverflow restrictions.)

4
  • thanks. It resolved the 404 issue but now https is striked through with a red line. I don't know why it is not recognizing my ssl (the path seems to be correct).
    – Phoenix
    Commented Dec 9, 2020 at 17:17
  • Did you only removed a line (my first suggestion) or totally modified server block?
    – KazikM
    Commented Dec 9, 2020 at 17:22
  • I tried both and that gave me the clue for what is happening (I am answering it bellow). Thanks again for your help.
    – Phoenix
    Commented Dec 10, 2020 at 10:17
  • Thanks a lot, i trying for 3 hours, and just remove return 404 for everything work Commented Feb 23 at 12:08
0

I finally figured out what is the problem.

I was creating certificate for www.mydomain.com, but in reality I my domain was set to mydomain.com (no www). I was redirecting to www but either I was doing it wrong or certbot does not like redirects of that nature.

Long story short, I (re)issued certificate for mydomain.com and certificate worked like a charm!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.