2

I have a reverse proxy server that takes file from fileserver than sends them to user. I want to change filename before sending. I wrote a rule like below

location ~ downloads/(.*) {          
        proxy_pass         http://HOST:PORT/remote.php/dav/files/$1;
        add_header Content-Disposition 'attachment; "filename=$args"';
   }

But when i send request i get this error;

ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION
  • Try [`proxy_ignore_header`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers) directive. – Ivan Shatsky Feb 01 '22 at 07:22
  • i tried that command like this; `proxy_ignore_headers Content-Disposition;` but nginx gives error `nginx: [emerg] invalid value "Content-Disposition" in nginx: [emerg] invalid value "Content-Disposition" in /conf/nginx.conf:96` – omer faruk kalkan Feb 01 '22 at 10:28
  • Try [`proxy_hide_header`](https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_hide_header) one. – Ivan Shatsky Feb 01 '22 at 10:32

1 Answers1

5

Adding a header with add_header works well with proxy pass, but if there is an existing header value in the response it will stack the values.

If you want to replace a header value (for example replace this Content-Disposition then you will have to do this in two steps:

# 1. hide the Content-Disposition from the server response
proxy_hide_header Content-Disposition;
# 2. add a new Content-Disposition header with your changes
add_header Content-Disposition 'attachment; "filename=$args"';

See my answer on a similar question here.

Wilt
  • 41,477
  • 12
  • 152
  • 203