1

I did follow the guide here, I'm using Tomcat 9 and Nginx 1.20.1 as proxy. However, I still cannot receive the reponse body when there is an error from Tomcat. My nginx config is as follow:

location / {
    proxy_pass http://tomcat;
    add_header  X-Upstream  $upstream_addr always;
    add_header 'Access-Control-Allow-Origin' $http_origin 'always';
    add_header 'Access-Control-Allow-Credentials' 'true' 'always';
    add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range' 'always';
    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH' 'always';

Update the case: so our app runs on Tomcat. When there is error 3xx or 5xx, we set the error status code and also send the error message (JSON) in the body. In this case, Nginx does not pass the response body to the client. The above configuration is supposed to tell Nginx to pass the response body even when there is error from Tomcat. However, it doesn't work.

Is there anything else I'm missing?

  • I did follow the guide here: https://stackoverflow.com/questions/14501047/how-to-add-a-response-header-on-nginx-when-using-proxy-pass – Ha Doan Ngoc Aug 23 '22 at 11:02
  • What do you mean by `Cannot receive response`? Are your requests timing out? Or you're getting a blank response while you were expecting some value in the body? Please post a sample curl request and response. – Rahul Sharma Aug 24 '22 at 02:07
  • When you visit the Response tab in the browser developer console, it shows this message: "Failed to load response data: No data found for the resource with given identifier" - It is not empty response, it is unable to load. And when you see the Headers tab, you only see Request Headers, no Response Header. Normally when there is server error (3xx or 5xx), we also send JSON message in the body. So when nginx is used as proxy, it does not pass the JSON message to the response. – Ha Doan Ngoc Aug 24 '22 at 04:54

0 Answers0