問題描述
安裝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!
參考文件