NGINX as a Reverse Proxy
[ 72 ]
Legacy servers with cookies
You may find yourself in a situation where you will need to place multiple legacy
applications behind one common endpoint. The legacy applications were written
for a case where they were the only servers talking directly with the client. They set
cookies from their own domain, and assumed that they would always be reachable
via the / URI. In placing a new endpoint in front of these servers, these assumptions
no longer hold true. The following configuration will rewrite the cookie domain and
path to match that of the new application endpoint:
server {
server_name app.example.com;
location /legacy1 {
proxy_cookie_domain legacy1.example.com app.example.com;
proxy_cookie_path $uri /legacy1$uri;
proxy_redirect default;
proxy_pass http://legacy1.example.com/;
}
The value of the $uri variable already includes the beginning
slash (/), so it is not necessary to duplicate it here.
location /legacy2 {
proxy_cookie_domain legacy2.example.org app.example.com;
proxy_cookie_path $uri /legacy2$uri;
proxy_redirect default;
proxy_pass http://legacy2.example.org/;
}
location / {
proxy_pass http://localhost:8080;
}
}