[Patch] Make resolver port configurable

Sirsiwal, Umesh usirsiwal at verivue.com
Fri Feb 11 06:19:39 MSK 2011


This path extends existing resolver command to optionally take a second parameter. The second parameter can be used to override default port 53.

-Umesh

diff -rupN tmp/nginx-0.8.53/src/http/ngx_http_core_module.c nginx-0.8.53/src/http/ngx_http_core_module.c
--- tmp/nginx-0.8.53/src/http/ngx_http_core_module.c    2010-10-18 10:14:00.000000000 +0000
+++ nginx-0.8.53/src/http/ngx_http_core_module.c        2011-02-04 19:07:32.000000000 +0000
@@ -679,7 +679,7 @@ static ngx_command_t  ngx_http_core_comm
       NULL },

     { ngx_string("resolver"),
-      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1|NGX_CONF_TAKE2,
       ngx_http_core_resolver,
       NGX_HTTP_LOC_CONF_OFFSET,
       0,
@@ -4338,6 +4338,7 @@ ngx_http_core_resolver(ngx_conf_t *cf, n

     ngx_url_t   u;
     ngx_str_t  *value;
+    ngx_int_t  port;

     if (clcf->resolver) {
         return "is duplicate";
@@ -4348,7 +4349,16 @@ ngx_http_core_resolver(ngx_conf_t *cf, n
     ngx_memzero(&u, sizeof(ngx_url_t));

     u.host = value[1];
-    u.port = 53;
+    if(cf->args->nelts == 3){
+      port = ngx_atoi(value[2].data, value[2].len);
+      if (port == NGX_ERROR || port == 0) {
+       ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                          "invalid resolver port \"%V\"", &value[2]);
+       return NGX_CONF_ERROR;
+      }
+      u.port = port;
+    }else
+      u.port = 53;

     if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V: %s", &u.host, u.err);



More information about the nginx-devel mailing list