首页 > 解决方案 > 带有letsencrypt的nginx入口:等待http-01质询传播:错误状态码'404',预期'200'

问题描述

我正在尝试从 GKE 重新部署到 Digital Ocean。我遇到了来自letsencrypt的挑战问题。我相信 K8s 告诉我找不到路由。Letencrypt 尝试进行质询但失败的两个主机名/域是 SendGrid 使用的 CNAMES。我不确定从哪里开始故障排除,我的 google-fu 让我失望了。

Namespace:    default
Labels:       <none>
Annotations:  <none>
API Version:  acme.cert-manager.io/v1alpha2
Kind:         Challenge
Metadata:
  Creation Timestamp:  2020-03-19T20:34:04Z
  Finalizers:
    finalizer.acme.cert-manager.io
  Generation:  1
  Owner References:
    API Version:           acme.cert-manager.io/v1alpha2
    Block Owner Deletion:  true
    Controller:            true
    Kind:                  Order
    Name:                  letsencrypt-certs-80407504-346698183
    UID:                   84ab9399-3a61-462e-a1c5-0831bd451a36
  Resource Version:        37060
  Self Link:               /apis/acme.cert-manager.io/v1alpha2/namespaces/default/challenges/letsencrypt-certs-80407504-346698183-813483524
  UID:                     ca14d996-3ecf-4dd8-8c53-057af7ae2b27
Spec:
  Authz URL:  https://acme-v02.api.letsencrypt.org/acme/authz-v3/3449670327
  Dns Name:   7502121.secodify.com
  Issuer Ref:
    Group:  cert-manager.io
    Kind:   ClusterIssuer
    Name:   letsencrypt-prod
  Key:      LiAawBR0bFRQfb2oXrvvNhph3ehQ-35lXJKkpjqgqb0.uWH4RnJfcABYba9T5b-QjoYnIw53rRtVhzsRIHIh39Y
  Solver:
    http01:
      Ingress:
        Class:  nginx
  Token:        LiAawBR0bFRQfb2oXrvvNhph3ehQ-35lXJKkpjqgqb0
  Type:         http-01
  URL:          https://acme-v02.api.letsencrypt.org/acme/chall-v3/3449670327/JGayWw
  Wildcard:     false
Status:
  Presented:   true
  Processing:  true
  Reason:      Waiting for http-01 challenge propagation: wrong status code '404', expected '200'
  State:       pending
Events:        <none>

我的配置图看起来像:

--- 
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
data:
  nginx.conf: |
    events {
      worker_connections  1024;
    }
    http {
      server {
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;
        listen 8080;
        server_name localhost;
        location ^~ /.well-known/acme-challenge/ {
          default_type "text/plain";
          rewrite /.well-known/acme-challenge/(.*) /$1 break;
        }
        location /static/ {
          autoindex on;    
          alias /code/core/static/; 
          include /etc/nginx/mime.types;
        }
        location = /favicon.ico {
        access_log off;
        log_not_found off;
        }
        location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_pass http://127.0.0.1:8080/;
        }
      }
    }
---```

标签: nginxkuberneteslets-encryptkubernetes-ingressnginx-ingress

解决方案


我在使用 Traefik 的 K3S 上遇到了同样的错误。原因是 DNS 和端口转发。Certmanager 在联系 Letsencrypt 之前会进行自我测试。如果我使用 Nginx 作为路由器,我会得到同样的错误。

我有:

  • 树莓派
  • 运行 Kubernetes
  • 在我的“DMZ”中
  • 使用端口转发到我的路由器上的端口 80/443 提供访问。

我在我的域提供商的 DNS 服务器中设置了几条 A 记录:

Certmanager 调用我的路由器来测试它的 Letsencrypt 功能,而不是在 Raspberry Pi 上测试它本身。

通过将 DNS 记录添加到我的域路由器的 DNS 服务器,使它们直接指向 Raspberry Pi 的内部 IP 地址,解决了这个问题。

当然:

  • 我的“DMZ”应该更加安全,并且路由器管理网站和内部网络应该无法从 Raspberry Pi 访问
  • 除了更新之外,我的树莓派应该无法启动与 Internet 的连接。

推荐阅读