使用 docker 和 nginx 设置反向代理时出现无限循环

问题描述

我正在使用 Docker 和 Nginx 设置反向代理。

我以页面 https://example.org/ 为例。

  1. 我在 /etc/hosts 中使用本地映射设置了自定义127.0.0.1 example.org

  2. 我如下设置了 docker-compose 文件

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
  1. 然后我设置了 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

我不知道哪个配置有问题:(

enter image description here

更新:

我还没有发现问题。

我决定使用 proxy_pass https://ip_address 而不是域名。我不明白为什么它在本地机器上与 Nginx 一起工作,但在 docker 中与 Nginx 一起工作

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)