We set up a nginx reverse proxy to handle request going to our app server. If a page is not found on the app server, the server returns a 404 and we send the request to our cms server, looking there for the page. This setup works so far, but we have problems when both proxied servers (app and cms) send a "Set-Cookie" header in the response, when the page is not found on the app server. Only the cookies from the cms server are send to the client.
Is it even possible to combine the "Set-Cookie" headers of both proxied servers? And if so, how is it done?
Our thoughts were to send the set-cookie response headers from the app server to the cms server and then and them there to the other cookies that are send to the client.
proxy_set_header App-Cookies $http_set_cookie;
But the set-cookie headers are not passed to the cms server.
server {
listen 443;
...
location / {
proxy_pass http://app;
proxy_pass_header Set-Cookie;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_connect_timeout 120;
proxy_send_timeout 120;
proxy_read_timeout 120;
send_timeout 120;
error_page 404 = @cms;
proxy_intercept_errors on;
}
location @cms {
proxy_pass http://cms;
proxy_pass_header Set-Cookie;
proxy_set_header Host $host:8081;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Scheme on;
# not working
proxy_set_header App-Cookies $http_set_cookie;
proxy_redirect http:// $scheme://;
}
}