我在容器 (Kubernetes) 中运行 Nginx 和 App。使用 NginX 入口点进行 TLS 握手,配置如下
upstream app {
server app:8200;
}
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /etc/ssl/util_example_com.crt;
ssl_certificate_key /etc/ssl/util_example_com.key;
ssl_client_certificate /etc/ssl/ca.crt;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_verify_client on;
location / {
proxy_pass http://app;
proxy_read_timeout 180;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
我可以curl http://app:8080/generator
从 Nginx 容器中执行此操作。但是,当我在公共端点上使用 curl () 执行相同操作时https://util.example.com/generator
,它会首先访问 Nginx,但504 Gateway Time-out
在 Nginx 中出现以下错误
2021/05/04 21:54:50 [error] 21#21: *1 upstream timed out (110: Connection timed out) while connecting to upstream, client: 10.2.16.183, server: localhost, request: "POST /generator HTTP/1.1", upstream: "http://172.20.154.113:8200/generator", host: "util.example.com"
有任何帮助吗,这里发生了什么事。
答案1
尝试删除所有不必要的部分。例如,尝试以下最小工作示例:(编辑 sub.domain.tld)
upstream app {
server app:8200;
}
server {
listen 443 ssl;
server_name sub.domain.tld;
ssl_certificate /etc/ssl/util_example_com.crt;
ssl_certificate_key /etc/ssl/util_example_com.key;
location / {
proxy_pass http://app;
}
}
从那里添加元素,直到找到导致超时的原因。