Syntax: resolver address ... [valid=time] [ipv6=on|off];
Default: -
Context: http, server, location
Example:resolve 119.29.29.29 8.8.8.8;
指令功能:配置name servers,nginx默认会域名解析IPV4和IPV6地址,如果不想解析ipv6,则可以添加ipv6=off来屏蔽。
备注:nginx默认是使用TTL来作为有效的时间,可以通过valid来修改。
Syntax:resolver_timeout time;
Default:resolver_timeout 30s;
Context:http, server, location
Example:resolver_timeout 10s;
指令功能:设置域名解析的超时时间,默认是30s。
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.1
CFLAGS="-g -O0" ./configure --prefix=/root/cjhust \
--with-debug \
--with-ipv6 \
--with-http_stub_status_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-pcre=addons/pcre-8.38 \
--with-openssl=addons/openssl-1.0.2h/ \
--with-ld-opt="-Wl,-rpath,$(LUAJIT_LIB)" \
--add-module=addons/lua-nginx-module-0.10.5 \
--add-module=addons/ngx_devel_kit-0.3.0
make
make install
server {
listen 9999;
location /test {
resolver 119.29.29.29 valid=1s;
resolver_timeout 5;
content_by_lua_block {
local sock = ngx.socket.tcp()
sock:settimeout(1000) #1s
local ok, err = sock:connect("www.google.com", 80)
if not ok then
ngx.say("failed to connect to google: ", err)
return
end
ngx.say("successfully connected to google!")
sock:close()
}
}
}