The normal solution to this is to tweak the app servers themselves to send their identity back in a custom http header.
We are in a special situation, in that the app server is a hard coded application, and we appear to not be able to get a new build of it with to do this. (On apache or iis it would be easy to solve, we would just add the header to the web server.)
So the question is, does nginx itself have the functionality to add a header to the response that informs the client which server serviced the request?
Note: This is not a normal "browser to web server" situation. This is a custom piece of client code (that we have source to and can modify) hitting a REST API on a monolithic , compiled, server (that we do not have source to and cannot modify). The client needs to know which server it hit, but does NOT need (or want) to go to the same server over and over (e.g. cookies are not the answer.... there are no cookies). The client just needs to be able to see in the response an indication of which server served that request.
Our nginx config is below. We are running the current GA build. We currently run nginx just as a load balancer, and on windows.
upstream appserver {
least_conn;
server 192.168.104.53:1124; // these are the IPs and ports of actual app servers
server 192.168.104.51:1124;
server 192.168.104.59:1124;
}
server {
listen 80; // this is where nginx listens
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://appserver;
}
I guess, you're looking for
$upstream_addr
variable.It will contain one of
192.168.104.xx:1124
.Yes, you use the
sticky
directive. For example:sticky cookie srv_id expires=1h domain=.example.com path=/;
This sets a cookie on the client, and for the next hour subsequent requests get sent to the right server. This goes in the upstream directive.
Source