微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决使用 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 举报,一经查实,本站将立刻删除。