尝试使用 Nginx 和 docker 将 LetsEncrypt 添加到用于 Spring boot 的域时出现未授权错误

尝试使用 Nginx 和 docker 将 LetsEncrypt 添加到用于 Spring boot 的域时出现未授权错误

我正在尝试使用 LetsEcnrypt 将 HTTPS 添加到我的域。到目前为止,我的服务器设置是,我在 Tomcat 上的 Docker 容器中运行 Spring Boot Port 8088,并且在 Tomcat 容器前面有 Nginx 服务器,允许访问Port 80Port 443。以下是我的配置文件

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 {  }

用于创建 nginx 容器的 Dockerfile

Dockerfile

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

我正在为 nginx 生成一个 docker 镜像,如下所示docker image build -t custom-nginx:latest .

然后我docker-compose.yml就像这样

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'

因此 nginx 正在监听Port 80Port 443并且 Spring Boot 正在运行Port 8088

我可以通过 http 访问该网站。DNS 映射已正确完成,但当我尝试使用此命令颁发证书时

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

我收到这个错误

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>\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.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是一个假设的站点,而不是原始站点。

这是我的问题。任何帮助都将不胜感激。谢谢

相关内容