0

I am using ngnix to proxy_pass the request to the app server. I am using the below configuration

server {
  listen       80;
  server_name  localhost;
  access_log  /var/log/nginx/localhost.access.log;
  location / {
             proxy_pass http://localhost:9000;
             proxy_http_version 1.1;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection 'upgrade';
             proxy_set_header Host $host;
             proxy_cache_bypass $http_upgrade;
            }
  location /names.json {
    proxy_pass      http://appserver.com:3000;
  }
  location /names/ {
    proxy_pass      http://appserver.com:3000;
  }
}

Now I have a POST request in the format: http://uiserver.com/hosts/export.xlsx

I am passing the params for the POST and making a POST request from my web server. Now when the app server returns the data in the form of excel, the browser is not loading with the data in the form of a file instead, I am seeing encrypted data in the response.

Is there something I am missing and how should I fix this? Or is it something form the app server end. Please let me know.

Thanks

zilcuanu
  • 2,601
  • 7
  • 36
  • 75

1 Answers1

0

The browser will use the Content-Type header to know what the content is (and how to handle it). Your application should send a Content-Type: application/<mimetype of your document>, see this question for correct types.

Without it (or with an incorrect one), the browser may try to display the content as text.

Community
  • 1
  • 1
David Duponchel
  • 3,563
  • 3
  • 22
  • 29
  • So apart from setting the content-type I dont need to do anything on the nginx in terms of proxy pass right? – zilcuanu Jul 13 '15 at 10:03
  • I tried setting the content-type. But still I am not getting the document when I try to POST using RestClient plugin. Do the app server also set the content and send the document? – zilcuanu Jul 13 '15 at 10:07
  • Nginx should pass this header as-it, you don't have to change anything here. The `Content-Type` header is set by the server in the response. With RestClient, you should see if you have this header and if it has a correct value. If not, that's your issue. – David Duponchel Jul 13 '15 at 10:13
  • I am seeing the content-type as "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" in the response. But still not able to get the file. I am using RestClient to test the API. Is there something else I am missing? – zilcuanu Jul 13 '15 at 10:34
  • I think that RestClient only handles text response, showing you random "text". If you have this header, the issue may be browser side. How do you call the document ? Do you send the user directly on its url ? Do you make an ajax call ? If so, could you add the code doing the call in your question ? – David Duponchel Jul 13 '15 at 15:48
  • I call the API through my UI server. I also pass the params and set the content type. – zilcuanu Jul 13 '15 at 16:20