Search code examples
nginxluaopenresty

nginx lua-resty-http no route to host error


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",
        headers = {
          ["Content-Type"] = "application/x-www-form-urlencoded",
        }
      })

How can I fix this Issue? Or is there any suggestion to make http request in nginx? any clue?

PS: There is a commented section in my Lua code. I also tried to make a request using that code but nothing happened.


Solution

  • Change the package_path like:

    lua_package_path "$prefix/resty_modules/lualib/?.lua;;";
    lua_package_cpath "$prefix/resty_modules/lualib/?.so;;";