我想用Nginx反向代理api。我有以下配置:Nginx proxy_pass返回[無主機],而反向代理
worker_processes 4;
events { worker_connections 1024; }
http {
upstream some_upstream {
server 1.something.com;
server 2.something.com;
}
server {
listen 80;
location ~/proxyNow/(?<zvar>(\w+))/(?<xvar>(\w+))/(?<yvar>(\w+))/ {
proxy_pass http://some_upstream/hello/something/$zvar/$xvar/$yvar/somethingelese;
proxy_set_header Host $http_host;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_cache maps_cache;
proxy_cache_valid 200 302 365d;
proxy_cache_valid 404 1m;
proxy_redirect off;
}
}
}
當我嘗試撥打以下網址http://localhost:82/proxyNow/1/2/3/?app_id=someAppId&app_code=someCode
我收到以下錯誤信息:
無效的URL
請求的URL 「 http://%5bNo%20Host%5d/hello/something/1/2/3/somethingelese「,是 無效。參考#9.be35dd58.1489086561.5c9bd3c
似乎主機不能被nginx檢索。但是,如果我直接執行呼叫:
http://1.something.com/hello/something/$zvar/$xvar/$yvar/somethingelese?app_id=someAppId&app_code=someCode
http://2.something.com/hello/something/$zvar/$xvar/$yvar/somethingelese?app_id=someAppId&app_code=someCode
看來,Nginx的出於某種原因無法解析主機
您有'proxy_set_header Host'和'proxy_cache_valid'重複的條目。你應該先嚐試糾正。 –