Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here is my server block from nginx.conf, I'm trying to rewrite my requests, which happens fine but my upstream hostname is not being set correctly, it always resolves to the actual IP address, but my API hosted as a virtual host in apache so end point always returns 500, any ideas how I can fix this?

listen 8090;

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;

here are the details from nginx logs in function <> while sending to client, client:, server:, 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:, server:, 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: attempt to concatenate field 'function_to_call_file' (a nil value)
stack traceback:
coroutine 0:
share|improve this question

Because you're setting the 'Host' header via proxy_set_header, you can change your proxy_pass directive to be the actual IP address of your backend server, rather than relying on DNS. Take for example;

location / { proxy_pass; proxy_set_header Host; # ..various other required directives omitted }

This will initiate a connection to on port 80, sending the Host header of If resolved to, it would be the same as:

location / { proxy_pass; }

Hope this helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.