【发布时间】:2019-02-20 15:12:43
【问题描述】:
我在 azure 云上成功配置了两个图像多容器实例,但在我的 nginx 访问日志中,我只检索了我认为是内部 IP (10.240.xxx.xx) 的内容。在为 nginx 实现了真正的 IP 包之后,这已经发生了。
我的猜测是容器实例隐藏在专用于特定池的公共负载均衡器后面。
我通过命令实例化容器实例:
az container create
这里是我的默认nginx配置:
user nginx;
worker_processes 1;
error_log /preferred/path/nginx_error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$proxy_add_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent "$http_referer" '
'"$http_user_agent"' ;
access_log /preferred/path/nginx_access.log main;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/conf.d/*.conf;
}
daemon off;
这里是我的站点配置:
server {
listen 80;
set_real_ip_from xxx.xx.xxx.x/xx;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
proxy_pass http://localhost:5000;
}
}
我从 cloudfare 帖子中设置了真实 IP。到目前为止,它似乎是最可靠和最新的。
有谁知道到底发生了什么?是否有可能通过任何其他标头获取真实的客户端 IP? 也有可能是我设置真实IP的方式有问题,但是我在网上找到的所有文档都让我很困惑。
【问题讨论】:
-
你用什么服务来运行它?
-
你到底是什么意思?正如我所写,我使用容器实例,如果这回答了您的问题。
-
不清楚你的设置是什么,你能分享你正在使用的CLI代码吗?你在使用 Azure 容器实例吗?是这样的吗? azure.microsoft.com/en-us/blog/…
-
我修改了帖子。我使用一个普通的容器实例。