Can’t use Certbot to SSL for Nginx with reactjs app and laravel subdirectory in subdomain

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.


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
   (IP): "<!DOCTYPE html>n<html lang="en">n<head>n
   <meta charset="UTF-8">n    <title>HelloWorld</title>n</head>n<body>nn</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
   (IP): "<html>rn<head><title>404 Not
   Found</title></head>rn<body>rn<center><h1>404 Not

How I can config nginx for ssl?

Thanks for support.