nginx lua-resty-http no route to host issue

523 views
Skip to first unread message

Grcn H

unread,
Oct 13, 2017, 9:11:06 PM10/13/17
to openresty-en
Hi there,

I'm trying to make an http request using lua-resty-http.
I created a simple get api in https://requestb.in

I can make a request using the address: https://requestb.in/snf2ltsn

However, when I try to do this in nginx I'm getting error  `no route to host`

My nginx.conf file is:

    worker_processes  1;
    error_log logs/error.log;
    events {
        worker_connections 1024;
    }
    http {
        lua_package_path "$prefix/lua/?.lua;;";
        server {
            listen 8080;
            location / {
                resolver 8.8.8.8;
                default_type text/html;
                lua_code_cache off; #enables livereload for development
                content_by_lua_file ./lua/test.lua;
            }
        }
    }

and my Lua code is 

    local http = require "resty.http"
    local httpc = http.new()
    
    --local res, err = httpc:request_uri("https://requestb.in/snf2ltsn", {ssl_verify = false,method = "GET" })
    
          local res, err = httpc:request_uri("https://requestb.in/snf2ltsn", {
            method = "GET",
            body = "a=1&b=2",
            headers = {
              ["Content-Type"] = "application/x-www-form-urlencoded",
            }
          })

How can I fix this Issue?
any clue?

Thanks in advance

Yichun Zhang (agentzh)

unread,
Oct 16, 2017, 3:25:14 PM10/16/17
to openresty-en
Hello!

On Fri, Oct 13, 2017 at 6:11 PM, Grcn H wrote:
>
> However, when I try to do this in nginx I'm getting error `no route to
> host`
>

I can see 2 possibilities:

1. The DNS server returns an IP address your network does not support
(like an IPv6 address), or
2. Your local network settings may have some issues.

You can try this instead:

resolver 8.8.8.8 ipv6=off;

BTW, temporarily enabling the nginx debugging logs can give your more
details about the DNS resolving results. You can use the
openresty-debug package temporarily and set `error_log logs/error.log
debug;` in your `nginx.conf` to enable debugging logs BTW.

Regards,
Yichun

Nithish Reddy

unread,
Nov 21, 2017, 5:12:31 AM11/21/17
to openresty-en
Hi am also using lua-resty-http:
it is giving error as "failed to request: example.com could not be resolved (110: Operation timed out)"
 local http = require "resty.http"
                                 local httpc = http.new ()
                                 local res, err = httpc:request_uri(
                                    "https://example.com/sample/samplePage/test"
                                        ,{
            method = "GET",
            body = "a=1&b=2",
            headers = {
              ["Content-Type"] = "application/x-www-form-urlencoded",
            }
          }
                                )

                                if not res then
                                        ngx.say("failed to request: ", err)
                                        return
                                end

                                if 200 == res.status then
                                    ngx.exit (res.status)
                                end

                                if 1 == res.body then
                                    ngx.say (" valid request ")
                                else
                                    ngx.say (" invalid request ")
                                end

Any solution ???
Reply all
Reply to author
Forward
0 new messages