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?