haiwen / seafile-docker

A Docker image for Seafile server
Other
544 stars 184 forks source link

Use $proxy_add_x_forwarded_for in nginx template for X-Forwarded-For header #167

Closed icpz closed 1 year ago

icpz commented 5 years ago

Hello, I'm in situation to put docker services behind a custom nginx frontend. This frontend will set the correct X-Forwarded-For header, but it's override by the nginx inside the docker image here.

Could you please replace that line with:

    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;

This will prevent the existing X-Forwarded-For from being changed, and set it to $remote_addr if not exist.

renfeipeng commented 5 years ago

Thank you for your suggestion, we will improve this configuration on the next release.

Redsandro commented 5 years ago

I think it would make sense to replace all X-Forwarded headers:

-        proxy_set_header Forwarded "for=$remote_addr;proto=$scheme";
+        proxy_set_header Forwarded "for=$proxy_add_x_forwarded_for;proto=$http_x_forwarded_proto";
-        proxy_set_header X-Forwarded-For $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
-        proxy_set_header X-Forwarded-Proto $scheme;
+        proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
-        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Real-IP $proxy_add_x_forwarded_for;

See https://github.com/haiwen/seafile-docker/issues/91#issuecomment-524914187