小编min*_*cos的帖子

docker 容器中的 Nginx 反向代理 - 记录了错误的 IP

我使用以下配置在 Docker 容器中运行 Nginx 作为反向代理。它基本上将请求重定向到在同一台机器上运行的另一个 docker 容器

问题

问题是访问日志中的输出指出了错误的客户端 IP 地址,特别是我获取了 Docker 主机的 IP 172.17.0.1

172.17.0.1 - - [24/May/2016:19:50:18 +0000] "GET /admin/ HTTP/1.1" 200 19243 "-" "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0" "-"

我试图遵循这篇文章中关于set_real_ip_from指令的建议,但没有任何成功。

配置

server {
    listen       8000 ssl;
    server_name  example.com;

    access_log  /var/log/nginx/host.access.log  main;

    ssl_certificate     /path/to/cert.pem;
    ssl_certificate_key /path/to/key.key;

    set_real_ip_from 172.17.0.1;
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;

    proxy_set_header    Host $host:$server_port;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto $scheme;

    location / {
        proxy_pass  http://172.17.0.1:8100/;
    } …
Run Code Online (Sandbox Code Playgroud)

nginx docker

8
推荐指数
1
解决办法
7249
查看次数

标签 统计

docker ×1

nginx ×1