简体   繁体   English

nginx page not found certbot安装后错误

[英]nginx page not found error after certbot installation

I have a http website (with Flask and nginx) which is up and running.我有一个正在运行的 http 网站(带有 Flask 和 nginx)。 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) .我正在尝试使用 certbot 安装certbot并按照他们的步骤导致安装成功消息(恭喜......)但刷新我的网页会导致404 Not Found nginx/1.18.0 (Ubuntu) This is the nginx.conf file after sudo certbot --nginx这是sudo certbot --nginx之后的nginx.conf文件

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.非常感谢任何帮助。

First, just remove this line:首先,只需删除此行:

return 404; # managed by Certbot

which causes 404 error to be returned.这会导致返回 404 错误。

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.) (由于一些奇怪的 StackOverflow 限制,我不得不将mydomain替换为yourdomain 。)

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).我正在为www.mydomain.com创建证书,但实际上我的域设置为mydomain.com (没有 www)。 I was redirecting to www but either I was doing it wrong or certbot does not like redirects of that nature.我正在重定向到www ,但要么我做错了,要么 certbot 不喜欢这种性质的重定向。

Long story short, I (re)issued certificate for mydomain.com and certificate worked like a charm!长话短说,我(重新)为mydomain.com颁发了证书,证书就像一个魅力!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM