nginx [emerg] invalid host in upstream

5,823 views
Skip to first unread message

Sunny GUPTA

unread,
Sep 5, 2015, 5:37:36 PM9/5/15
to openresty-en
#### nginx.conf

http {



    lua_package_path "./lua/?.lua;;";

    resolver 8.8.8.8;

    #Basic reverse proxy server
    upstream backend{
        server  http://0.0.0.0:5000/api/v1/ssjs; #some remote server
    }


    server {
        listen 8080;
        lua_code_cache off; # for development only

        location / {
            content_by_lua_file ./lua/nginx_ss.lua;
        }

        #Proxy_pass the request to remote server
        location /v1/secure/proxy_shield_square/ {
            internal;
            resolver 8.8.8.8;
            #### Any remote server end-point
            proxy_set_header HOST $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_pass   http://backend;
            #proxy_pass  http://some.remoteserver.com/serverendpoint;
            # http://0.0.0.0:5000/api/v1/ssjs;
        }

    }


#in nginx_ss.lua file . I am catching incoming req making some changes in header, setting new body and passing to location.capture 
# /v1/secure/proxy_shield_square/ that is supposed to proxy pass my request to remote server

#############################################
# this is nginx_ss.lua 

# body preparation as string in json format
local final_json = table.concat(api_table);
--ngx.print(final_json);

ngx.req.read_body();

local res = ngx.location.capture("/v1/secure/proxy_shield_square/", { body = final_json });
ngx.say("\n\n--------Response Headers from Remote server-------------");
ngx.say("status : ", res.status);
ngx.say("method : ", res.method);
ngx.say("body :", res.body);

for k,v in pairs(res.header) do
    ngx.say(k,'-', v);
end

##################################################
Command to reload nginx conf
$ nginx -p `pwd` -s reload

nginx: [emerg] invalid host in upstream "http://0.0.0.0:5000/api/v1/ssjs" in /home/lautner/CodeCave/open_nginx/conf/nginx.conf:15

Is there is something wrong i am doing right now?
when i proxy_pass directly this http://0.0.0.0:5000/api/v1/ssjs , i am getting all request at this running server locally. 
but when using upstream directive, it throwing this above error. Please someone having this knowledge regarding this issue, help me out? Thanks%


DeJiang Zhu

unread,
Sep 5, 2015, 9:59:21 PM9/5/15
to openre...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sunny GUPTA

unread,
Sep 6, 2015, 7:17:38 AM9/6/15
to openresty-en
Thanks DeJiang, its working now.. But what about my actual server endpoint. that is something like http://servername.com/getdata ; do i need to mention the ip address of that server_name that correspond to that server?
Reply all
Reply to author
Forward
0 new messages