nginx lua-resty-http 没有路由到主机错误
nginx lua-resty-http no route to host error
我正在尝试使用 lua-resty-http 发出 http 请求。
我在 https://requestb.in
中创建了一个简单的 get api
我可以使用地址提出请求:https://requestb.in/snf2ltsn
但是,当我尝试在 nginx 中执行此操作时,出现错误 no route to host
我的 nginx.conf 文件是:
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;
}
}
}
我的 Lua 代码是
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",
}
})
我该如何解决这个问题?
或者是否有任何建议在 nginx 中发出 http 请求?
有什么线索吗?
PS: 我的 Lua 代码中有一个注释部分。我也尝试使用该代码发出请求,但没有任何反应。
默认 nginx 解析器 returns 给定域的 IPv4 和 IPv6 地址。
resty.http 模块使用 cosocket API.
Cosocket 用域名调用的connect 方法选择了一个随机的IP 地址你不走运,它选择了IPv6 地址。您可以通过查看 nginx error.log
来检查它
很可能 IPv6 在您的盒子上不工作。
要为 nginx 解析器禁用 IPv6,请在您的位置使用以下指令:
resolver 8.8.8.8 ipv6=off;
将 package_path 更改为:
lua_package_path "$prefix/resty_modules/lualib/?.lua;;";
lua_package_cpath "$prefix/resty_modules/lualib/?.so;;";
我正在尝试使用 lua-resty-http 发出 http 请求。 我在 https://requestb.in
中创建了一个简单的 get api我可以使用地址提出请求:https://requestb.in/snf2ltsn
但是,当我尝试在 nginx 中执行此操作时,出现错误 no route to host
我的 nginx.conf 文件是:
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;
}
}
}
我的 Lua 代码是
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",
}
})
我该如何解决这个问题? 或者是否有任何建议在 nginx 中发出 http 请求? 有什么线索吗?
PS: 我的 Lua 代码中有一个注释部分。我也尝试使用该代码发出请求,但没有任何反应。
默认 nginx 解析器 returns 给定域的 IPv4 和 IPv6 地址。
resty.http 模块使用 cosocket API.
Cosocket 用域名调用的connect 方法选择了一个随机的IP 地址你不走运,它选择了IPv6 地址。您可以通过查看 nginx error.log
来检查它很可能 IPv6 在您的盒子上不工作。
要为 nginx 解析器禁用 IPv6,请在您的位置使用以下指令:
resolver 8.8.8.8 ipv6=off;
将 package_path 更改为:
lua_package_path "$prefix/resty_modules/lualib/?.lua;;";
lua_package_cpath "$prefix/resty_modules/lualib/?.so;;";