我有以下 Docker 设置:
jwilder/nginx-proxy 用于反向代理
jrcs/letsencrypt-nginx-proxy-companion 用于 SSL (Let's Encrypt)
自定义 WildFly 容器作为端点
我的问题是,访问网站时会抛出 504 错误。我为 WildFly 容器提供了环境变量,其中包含多个 VIRTUAL_HOST、LETSENCRYPT_HOST 和 LETSENCRYPT_EMAIL。我尝试公开端口,但没有帮助。端口 8080 显示在中docker ps -a
。权重、max_fails 等来自我在网上找到的教程,因为它对我来说不起作用,我认为它可以修复它。使用 curl IP:8080 会得到成功的响应。
我的容器中的 Nginx 配置:
# wildfly.example.com
upstream wildfly.example.com {
# Cannot connect to network of this container
server 172.17.0.5:8080 weight=100 max_fails=5 fail_timeout=5;
}
server {
server_name wildfly.example.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
# Do not HTTPS redirect Let'sEncrypt ACME challenge
location /.well-known/acme-challenge/ {
auth_basic off;
allow all;
root /usr/share/nginx/html;
try_files $uri =404;
break;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
server_name wildfly.example.com;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/wildfly.example.com.crt;
ssl_certificate_key /etc/nginx/certs/wildfly.example.com.key;
ssl_dhparam /etc/nginx/certs/wildfly.example.com.dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/certs/wildfly.example.com.chain.pem;
add_header Strict-Transport-Security "max-age=31536000" always;
include /etc/nginx/vhost.d/default;
location / {
proxy_pass http://wildfly.example.com;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $server_addr:$server_port;
proxy_set_header X-Real-IP $remote_addr;
}
}
PS 之所以出现无法连接网络的注释,是因为它没有自动检测服务器,因此我不得不手动编辑内部 IP。我的docker logs nginxcontainerid
输出:
2020/06/04 14:14:37 [error] 22247#22247: *6228 upstream timed out (110: Connection timed out) while connecting to upstream, client: IPHERE, server: wildfly.example.com, request: "GET / HTTP/2.0", upstream: "http://172.17.0.5:8080/", host: "wildfly.example.com"
答案1
我不熟悉 WildFly,但该应用程序会接受带有 wildlfy.example.com 标头的请求吗?您正在使用 IP 对容器上的 :8080 进行 CURL 操作,WildFly 服务器可能也需要设置为接受来自域本身的请求。504 错误通常是服务器由于配置不正确或无法访问而丢弃您的请求,这取决于您的 CURL。我会在您的 WildFly 容器内查找问题。