I am attempting to set up an NGINX proxy to redirect all requests to one of two servers based on the contents of a query string argument. Essentially:
https://my.site.com/api/...&server=a
should redirect to
https://a.site.com/api/...&server=a
and
https://my.site.com/api/...&server=b
should redirect to
https://b.site.com/api/...&server=b
I appear to have a config that does the basic work of rewriting the hostname and keeping the query string intact:
error_log /dev/stdout info;
worker_processes 1;
events {
worker_connections 1024;
accept_mutex off;
}
http {
access_log /dev/stdout combined;
sendfile on;
server {
listen 443 ssl;
server_name $hostname;
ssl_certificate /etc/ssl/nginx.crt;
ssl_certificate_key /etc/ssl/nginx.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
location ~ /api/ {
if ($arg_server !~ "^(a|b)$") { return 404; }
rewrite ^ $scheme://my.site.$arg_server.com$uri;
}
}
}
However, I cannot seem to get all the headers in the original request to survive the journey -- the Authorization
header, for example, does not seem to arrive at https://[server].site.com/api/...
My understanding was that all headers were kept by default? Is that not true?