我在 1 個 IP 上有網域,在其他 IP 上有子網域。我配置了 FE 的 nginx url:http://subdomain/ 和 BE:http://subdomain/api。我需要 ssl 來使用子網域證書機器人,此時我有FE 反應應用程式和php laravel BE 版全部投入泊塢窗,但沒有成功。
nginx.conf
server {
listen 8888;
server_name subdomain;
index index.php index.html;
root /var/www;
client_max_body_size 256M;
error_log /var/log/nginx/fe/error.log;
access_log /var/log/nginx/fe/access.log;
## config path for API
location ^~ /api {
error_log /var/log/nginx/api/error.log;
access_log /var/log/nginx/api/access.log;
alias /var/www/api/public;
if (!-e $request_filename) {
rewrite ^ /api/index.php last;
}
location ~ \.php$ {
if (!-f $request_filename) {
return 404;
}
fastcgi_pass api:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
location ~ /.well-known/acme-challenge {
allow all;
default_type "text/plain" ;
alias /var/www/certbot/index.html; <-- #here only static file html with "HelloWorld"
}
## Load staic file for FE
location / {
try_files $uri /index.html;
}
}
當我運行驗證時nginx 的 ssl經過證書機器人:
certbot --nginx -d <subdomain> -m <email>
我有錯誤如下:
Domain: <subdomain>
Type: unauthorized
Detail: Invalid response from
http://<sudomain>/.well-known/acme-challenge/88C3jgQzqOTXDqBbDX_XLZRR0Sw5RGaNUaGyCgedwVs
[IP]: "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n
<meta charset=\"UTF-8\">\n <title>HelloWorld</title>\n</head>\n<body>\n\n</body>"
如果我在 nginx 中設定區塊/.well-known/acme-challenge
僅allow all;
或allow all; root /certbot/index.html;
我有錯誤
Domain: <subdomain>
Type: unauthorized
Detail: Invalid response from
http://<subdomain>/.well-known/acme-challenge/bfp9WEdPO1eb4NPTSPuQCD2jpakgn2-aIUVF62nrwLs
[IP]: "<html>\r\n<head><title>404 Not
Found</title></head>\r\n<body>\r\n<center><h1>404 Not
Found</h1></center>\r\n<hr><center>nginx/1.15.12</c"
如何為 ssl 設定 nginx?
感謝你的支持。
答案1
更新:
我修好了它。因為我在Docker中設定了nginx和certbot並在沒有443連接埠的情況下運行容器。打開地圖443和80端口,它就像魅力一樣。