Nginx(docker 容器)后面的 Owncloud 未记录远程客户端 IP

Nginx(docker 容器)后面的 Owncloud 未记录远程客户端 IP

由于某种原因,Nginx 反向代理后面的 Owncloud 容器没有记录远程客户端 IP,而是记录了 Nginx IP。请查看下面我的 Nginx 配置文件。我尝试了多种解决方案来修改 Nginx proxy_set_headers 指令,但均未成功。

Nginx 服务器正确地将标头发送到 Owncloud 服务器:

  "HTTP Headers Information": {
        "HTTP Request": "GET \/apps\/configreport\/report HTTP\/1.1",
        "X-Real-IP": "CLIENT_IP",
        "X-Forwarded-For": "CLIENT_IP",
        "X-Forwarded-Proto": "https",
        "X-Forwarded-Host": "mydomain:port",
        "X-Forwarded-Ssl": "on",

但是,REMOTE_ADDRApache 环境中的 var 被设置为 Nginx 服务器 IP。

我尝试在 Owncloud docker 镜像中加载 RemoteIP 模块,但 Nginx IP 仍然被记录。

有任何想法吗?

Nginx.conf:

server {
listen 8989 ssl;
listen [::]:8989 ssl;

server_name _;

add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive";
include /config/nginx/ssl.conf;

client_max_body_size 0;

server_tokens off;
more_clear_headers Server;

location / {
    proxy_pass http://owncloud:8080;
    include /config/nginx/proxy.conf;
}
}

代理.conf:

client_body_buffer_size 128k;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
send_timeout 5m;
proxy_read_timeout 240;
proxy_send_timeout 240;
proxy_connect_timeout 240;
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 https;
proxy_set_header X-Forwarded-Host $http_host;
proxy_set_header X-Forwarded-Ssl on;
proxy_redirect  http://  $scheme://;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_cache_bypass $cookie_session;
proxy_no_cache $cookie_session;
proxy_buffers 32 4k;
proxy_headers_hash_bucket_size 128;
proxy_headers_hash_max_size 1024;

答案1

我设法通过将 Apache 的日志格式更改为来捕获真实 IP

LogFormat "%{X-Forwarded-For}i %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\ " combine

相关内容