nginx proxy_pass设置主机名

这是我从nginx.conf的服务器块,我试图重写我的请求,这发生很好,但我的上游主机名没有被正确设置,它总是parsing为实际的IP地址,但我的API托pipe作为虚拟主机在Apache所以终点总是返回500,任何想法如何我可以解决这个问题?

listen 8090; server_name example.dev.xyz.com; set $api_path http://example-dev/api; location ~ ^/api/ { rewrite ^/api/(.*) /$1 break; proxy_pass $api_path; proxy_redirect off; proxy_set_header Host $server_name ; proxy_set_header X-Real-IP $remote_addr ; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } 

这里是来自nginx日志的细节

  ...top/api-aggregator-master/sandbox/lua/system/sandbox.lua: in function <...top/api-aggregator-master/sandbox/lua/system/sandbox.lua:1> while sending to client, client: 127.0.0.1, server: example.dev.xyz.com, request: "GET /aggr/conversations HTTP/1.1", host: "localhost:8090" 2013/10/02 09:21:57 [warn] 27711#0: *8 an upstream response is buffered to a temporary file /Users/santthosh.selvadurai/Desktop/api-aggregator-master/sandbox/proxy_temp/4/00/0000000004 while reading upstream, client: 127.0.0.1, server: example.dev.xyz.com, request: "GET /aggr/conversations HTTP/1.1", subrequest: "/v1/GetTopicPage", upstream: "http://XX.XX.110.48:80/api", host: "localhost:8090" 2013/10/02 09:21:57 [error] 27711#0: *8 lua entry thread aborted: runtime error: ...top/api-aggregator-master/sandbox/lua/system/sandbox.lua:86: attempt to concatenate field 'function_to_call_file' (a nil value) stack traceback: coroutine 0: 

由于您通过proxy_set_header设置“主机”标题,因此可以将proxy_pass指令更改为后端服务器的实际IP地址,而不是依赖于DNS。 举个例子,

 location / { proxy_pass http://10.0.0.2; proxy_set_header Host www.example.com; # various other required directives omitted } 

这将在端口80上启动到10.0.0.2的连接,发送www.example.comHost头。 如果www.example.comparsing为10.0.0.2 ,则将与以下内容相同:

 location / { proxy_pass http://www.example.com; } 

希望这可以帮助。