我想使用nginx作为转发代理,但是根据标头值重写URL(也是主机部分)。 假设浏览器通过常规http请求连接到端口8888上的nginx。标头是一对:
X-myattribute: https://somehost.com
nginx应该proxy_pass到https://somehost.com
我的nginx.conf现在是:
server {
listen 8888;
proxy_connect;
proxy_max_temp_file_size 0;
resolver 8.8.8.8;
location / {
proxy_pass https://$http_myattribute;
# proxy_pass http://$http_host$uri$is_args$args;
proxy_set_header Host $http_host;
}
}
}
但是我得到了
2018/08/16 19:44:08 [error] 9#0: *1 invalid port in upstream "https://somehost.com:443", client: 172.17.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8888"
2018/08/16 19:47:25 [error] 9#0: *1 invalid URL prefix in "https://somehost.com:443", client: 172.17.0.1, server: , request: "GET / HTTP/1.1", host: "localhost:8888"
(两行取决于我是否设置了
proxy_pass http://$X-myattribute或
proxy_pass https://$X-myattribute或
proxy_pass $X-myattribute。假设X-myattribute始终具有http://或https://) >
有什么建议吗?