将子域映射到子目录和自定义标头以进行基本身份validation

我有一个客户端库,我需要支持这个硬编码子目录和自定义头authentication方法。 服务器已经使用子目录的其他东西,所以我想映射子域+子目录到不同的子目录。 服务器使用基本身份validation。

我已经正确地将子域重写到备用子目录,但是我在身份validation方面遇到了问题。 我目前在自定义标头中传递了base64编码的“user:pass”,并尝试使用proxy_set_header设置auth标头。 如何使用自定义标头中的值进行基本身份validation?

 server { server_name subdomain.example.com; listen 443; ssl on; ssl_certificate /etc/nginx/ssl/example.crt; ssl_certificate_key /etc/nginx/ssl/example.key; rewrite ^/hardcodesubdir/(.*)$ https://example.com/newsubdir/$1; proxy_set_header Authorization "Basic $http_x_custom_header"; } 

我设法让它在一个位置的proxy_pass工作

 server { server_name subdomain.example.com; listen 443; ssl on; ssl_certificate /etc/nginx/ssl/example.crt; ssl_certificate_key /etc/nginx/ssl/example.key; location /hardcodesubdir/ { proxy_set_header Authorization "Basic $http_x_custom_header"; proxy_pass https://example.com/newsubdir/ } }