Unauthorized error while trying to add LetsEncrypt to a domain using Nginx with docker for Spring boot

I am trying to add HTTPS to my domain using LetsEcnrypt. My server setup so far is, I have Spring Boot running on Tomcat in a docker container on Port 8088 and I have Nginx server in front of the Tomcat container which is allowed to access Port 80 and Port 443.
Here are my configuration files

nginx.conf

http{
server {
        listen 80;
        listen [::]:80;


        location / {
             proxy_pass        http://blab:8088;
             proxy_set_header  X-Real-IP $remote_addr;
             proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header  Host $http_host;
        }
        location /.well-known/acme-challenge/ {
            root /var/www/certbot;
        }
}
server {
    listen              443 ssl;
    server_name         blab.com;
    ssl_certificate     /etc/letsencrypt/live/blab.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/blab.com/privkey.pem;

    location / {
             proxy_pass        http://blab:8088;
             proxy_set_header  X-Real-IP $remote_addr;
             proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header  Host $http_host;
    }
}
}
events {  }

Dockerfile for creating a nginx container

Dockerfile

# latest nginx
FROM nginx
# copy custom configuration file
COPY nginx.conf /etc/nginx/nginx.conf
# expose server port
EXPOSE 80
# start server
CMD ["nginx", "-g", "daemon off;"]

I am generating a docker image for nginx like this docker image build -t custom-nginx:latest .

Then I have docker-compose.yml like this

version: '3.7'

services:

  nginx_server:
    image: custom-nginx
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - ./data/nginx:/etc/nginx/conf.d
      - ./data/certbot/conf:/etc/letsencrypt
      - ./data/certbot/www:/var/www/certbot
    depends_on:
      - "blab"

  blab:
    image: joker/blab
    ports:
      - '8088:8088'

So nginx is listening to Port 80 and Port 443 and Spring Boot is running on Port 8088

I can access the site on http. DNS mapping is correctly done but when I try to issue a certificate using this command

docker run -it --rm --name certbot 
            -v "/data/certbot/conf:/etc/letsencrypt" 
            -v "/data/certbot/www:/var/www/certbot" 
            certbot/certbot certonly

I get this error

Challenge failed for domain blab.com
http-01 challenge for blab.com
Cleaning up challenges
Some challenges have failed.

IMPORTANT NOTES:
 - The following errors were reported by the server:

   Domain: blab.com
   Type:   unauthorized
   Detail: Invalid response from
   http://blab.com/.well-known/acme-challenge/sdaglkoweg235362gnvoerg
   [my_ip]: "<html>rn<head><title>404 Not
   Found</title></head>rn<body>rn<center><h1>404 Not
   Found</h1></center>rn<hr><center>nginx/1.17.8</ce"

   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A/AAAA record(s) for that domain
   contain(s) the right IP address.

blab.com is a hypothetical site, not the original site.

This is my problem. Any help on this would be hugely appreciated. Thanks

Source: StackOverflow