如何解决使用 docker 和 nginx 设置反向代理时出现无限循环
我正在使用 Docker 和 Nginx 设置反向代理。
我以页面 https://example.org/
为例。
version: '3'
services:
Nginx:
image: Nginx:latest
container_name: nginx-reverse-proxy
volumes:
- ./Nginx.conf:/etc/Nginx/Nginx.conf
- ./Nginx-selfsigned.crt:/etc/Nginx/Nginx-selfsigned.crt
- ./Nginx-selfsigned.key:/etc/Nginx/Nginx-selfsigned.key
ports:
- 80:80
- 443:443
- 然后我设置了
Nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80 default_server;
listen 443 ssl;
ssl_certificate Nginx-selfsigned.crt;
ssl_certificate_key Nginx-selfsigned.key;
server_name example.org;
add_header Last-Modified $date_gmt;
proxy_cache_bypass 1;
location / {
add_header X-Upstream 'default docker' always;
proxy_pass https://example.org;
proxy_ssl_server_name on;
}
}
include servers/*;
}
但是在我运行 docker compose up
然后我访问页面 https://example.org
我收到了 502 bad gateway
错误,其中添加了许多我配置的标头 X-Upstream: default docker
更新:
我还没有发现问题。
我决定使用 proxy_pass https://ip_address
而不是域名。我不明白为什么它在本地机器上与 Nginx 一起工作,但在 docker 中与 Nginx 一起工作
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。