我有 1 个 IP 的域和其他 IP 的子域。我为 FE:http://subdomain/ 和 BE:http://subdomain/api 配置了 nginx url。我需要 ssl 子域使用Certbot,在这个我有反应应用程序 FE和php laravel BE都在docker,但没有成功。
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;
}
}
当我通过Certbot为 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>"
/.well-known/acme-challenge
如果我在 nginx 中设置 block onlyallow 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?
谢谢你的支持。
更新:
我修好了它。因为我在 Docker 中设置了 nginx 和 certbot 并在没有 443 端口的情况下运行容器。打开地图 443 和 80 端口,它像魅力一样工作。