安裝certbot後找不到nginx頁面錯誤 (nginx page not found error after certbot installation)


問題描述

安裝certbot後找不到nginx頁面錯誤 (nginx page not found error after certbot installation)

我有一個正在運行的 http 網站(帶有 Flask 和 nginx)。我正在嘗試使用 certbot 安裝 ssl 並按照他們的步驟導致安裝成功消息(恭喜...)但刷新我的網頁會導致 404 Not Found nginx/1.18.0 ( Ubuntu)</代碼>。這是 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


}

任何幫助之後的 nginx.conf 文件。


參考解法

方法 1:

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.)

方法 2:

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!

(by MikeKazikMMike)

參考文件

  1. nginx page not found error after certbot installation (CC BY‑SA 2.5/3.0/4.0)

#Certbot #Flask #SSL #nginx-location #nginx






相關問題

certbot-auto /letsencrypt 為指向同一服務器的多個域設置一個密鑰 (certbot-auto / letsencrypt setting up one key for multiple domains pointing to the same server)

certbot 工作時 Phpseclib 早期執行 (Phpseclib early execution while certbot working)

“httpd.service 的作業失敗,因為控制進程以錯誤代碼退出。” 我該如何解決? ("Job for httpd.service failed because the control process exited with error code." How do I fix this?)

無法使用 certbot renew/Letsencrypt 續訂證書 (Cannot renew certificates with certbot renew/Letsencrypt)

為 AWS 中託管的網站設置 HTTPS,但指向局域網中的 webAPI (Setting up HTTPS for a website hosted in AWS, but points to a webAPI in the local area network)

docker 發送內部 cerbot 日誌文件到主機 journald (docker send internal cerbot log file to host journald)

Nginx 允許來自任何域的流量 (Nginx allow traffic from any domain)

如何有效地為 2 個遠程節點使用 Kubernetes (How to use Kubernetes effectively for 2 distant nodes)

如何在 docker 映像中創建目錄? (How can I make dir inside docker image?)

更新 Certbot 時出現“連接超時(可能是防火牆問題)” ("Timeout during connect (likely firewall problem)" while renewing Certbot)

安裝certbot後找不到nginx頁面錯誤 (nginx page not found error after certbot installation)

Nginx 和 certbot 的 ERR_SSL_PROTOCOL_ERROR (ERR_SSL_PROTOCOL_ERROR with Nginx & certbot)







留言討論