I have domain at 1 IP and subdomain at other IP. I had config nginx url for FE: http://subdomain/ and for BE: http://subdomain/api. And I need ssl for subdomain use Certbot, at this I have react app for FE and php laravel for BE all in docker, but not successfull.
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;
}
}
And when I run verify ssl for nginx by Certbot:
certbot --nginx -d <subdomain> -m <email>
I have error as bellow:
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>"
If I set block /.well-known/acme-challenge
in nginx with only allow all;
or allow all; root /certbot/index.html;
I have error
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"
How I can config nginx for ssl?
Thanks for support.