]> git.kaiwu.me - nginx.git/commitdiff
merge r2990, r3324, r3384, r3419:
authorIgor Sysoev <igor@sysoev.ru>
Mon, 1 Feb 2010 14:01:24 +0000 (14:01 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 1 Feb 2010 14:01:24 +0000 (14:01 +0000)
various proxy/FastCGI fixes:

*) do auto redirect for proxy_pass/fastcgi_pass with variables
*) allow "proxy_pass  http://$backend" without URI part
*) add conf/fastcgi.conf
*) delete u->cleanup mark, this fixes large values in $upstream_response_time,
   the bug had been introduced in r3246

auto/install
conf/fastcgi.conf [new file with mode: 0644]
src/http/modules/ngx_http_fastcgi_module.c
src/http/modules/ngx_http_proxy_module.c
src/http/ngx_http_upstream.c

index f876891f811463044016054042c4cfb1fedefcb2..815fcb33580e7c9126fab6945ed0feed20195ba6 100644 (file)
@@ -101,6 +101,10 @@ install:   $NGX_OBJS${ngx_dirsep}nginx${ngx_binext} \
        cp conf/fastcgi_params \
                '\$(DESTDIR)$NGX_CONF_PREFIX/fastcgi_params.default'
 
+       test -f '\$(DESTDIR)$NGX_CONF_PREFIX/fastcgi.conf' \
+               || cp conf/fastcgi.conf '\$(DESTDIR)$NGX_CONF_PREFIX'
+       cp conf/fastcgi.conf '\$(DESTDIR)$NGX_CONF_PREFIX/fastcgi.conf.default'
+
        test -f '\$(DESTDIR)$NGX_CONF_PATH' \
                || cp conf/nginx.conf '\$(DESTDIR)$NGX_CONF_PATH'
        cp conf/nginx.conf '\$(DESTDIR)$NGX_CONF_PREFIX/nginx.conf.default'
diff --git a/conf/fastcgi.conf b/conf/fastcgi.conf
new file mode 100644 (file)
index 0000000..fab09eb
--- /dev/null
@@ -0,0 +1,24 @@
+
+fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
+fastcgi_param  QUERY_STRING       $query_string;
+fastcgi_param  REQUEST_METHOD     $request_method;
+fastcgi_param  CONTENT_TYPE       $content_type;
+fastcgi_param  CONTENT_LENGTH     $content_length;
+
+fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
+fastcgi_param  REQUEST_URI        $request_uri;
+fastcgi_param  DOCUMENT_URI       $document_uri;
+fastcgi_param  DOCUMENT_ROOT      $document_root;
+fastcgi_param  SERVER_PROTOCOL    $server_protocol;
+
+fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
+fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
+
+fastcgi_param  REMOTE_ADDR        $remote_addr;
+fastcgi_param  REMOTE_PORT        $remote_port;
+fastcgi_param  SERVER_ADDR        $server_addr;
+fastcgi_param  SERVER_PORT        $server_port;
+fastcgi_param  SERVER_NAME        $server_name;
+
+# PHP only, required if PHP was built with --enable-force-cgi-redirect
+fastcgi_param  REDIRECT_STATUS    200;
index 3ce608db19fb21060219af7019c4c83f496d5e9a..bdc52b644cbcaed5aa121fe38778f865a13ac55f 100644 (file)
@@ -2433,8 +2433,13 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
     }
 
     clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
+
     clcf->handler = ngx_http_fastcgi_handler;
 
+    if (clcf->name.data[clcf->name.len - 1] == '/') {
+        clcf->auto_redirect = 1;
+    }
+
     value = cf->args->elts;
 
     url = &value[1];
@@ -2470,10 +2475,6 @@ ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         return NGX_CONF_ERROR;
     }
 
-    if (clcf->name.data[clcf->name.len - 1] == '/') {
-        clcf->auto_redirect = 1;
-    }
-
     return NGX_CONF_OK;
 }
 
index f4ed8a7a1b82b99e228ab8922f68fd8c8bfa8c8d..9da8b4c55f35f976a37bf6ff9d3313f20f2c2ed0 100644 (file)
@@ -717,17 +717,22 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,
         return NGX_ERROR;
     }
 
-    if (url.uri.len && url.uri.data[0] == '?') {
-        p = ngx_pnalloc(r->pool, url.uri.len + 1);
-        if (p == NULL) {
-            return NGX_ERROR;
-        }
+    if (url.uri.len) {
+        if (url.uri.data[0] == '?') {
+            p = ngx_pnalloc(r->pool, url.uri.len + 1);
+            if (p == NULL) {
+                return NGX_ERROR;
+            }
+
+            *p++ = '/';
+            ngx_memcpy(p, url.uri.data, url.uri.len);
 
-        *p++ = '/';
-        ngx_memcpy(p, url.uri.data, url.uri.len);
+            url.uri.len++;
+            url.uri.data = p - 1;
+        }
 
-        url.uri.len++;
-        url.uri.data = p - 1;
+    } else {
+        url.uri = r->unparsed_uri;
     }
 
     ctx->vars.key_start = u->schema;
@@ -2585,6 +2590,12 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
 
+    clcf->handler = ngx_http_proxy_handler;
+
+    if (clcf->name.data[clcf->name.len - 1] == '/') {
+        clcf->auto_redirect = 1;
+    }
+
     value = cf->args->elts;
 
     url = &value[1];
@@ -2613,8 +2624,6 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
         }
 #endif
 
-        clcf->handler = ngx_http_proxy_handler;
-
         return NGX_CONF_OK;
     }
 
@@ -2661,8 +2670,6 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     ngx_http_proxy_set_vars(&u, &plcf->vars);
 
-    clcf->handler = ngx_http_proxy_handler;
-
     plcf->location = clcf->name;
 
     if (clcf->named
@@ -2686,10 +2693,6 @@ ngx_http_proxy_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
 
     plcf->url = *url;
 
-    if (clcf->name.data[clcf->name.len - 1] == '/') {
-        clcf->auto_redirect = 1;
-    }
-
     return NGX_CONF_OK;
 }
 
index ed86a382ca11a63888b2a109c00d0d88b1b679f3..943ef69e8b15ec223eb559b0b149fff73f50ece8 100644 (file)
@@ -364,6 +364,7 @@ ngx_http_upstream_create(ngx_http_request_t *r)
     if (u && u->cleanup) {
         ngx_http_upstream_cleanup(r);
         *u->cleanup = NULL;
+        u->cleanup = NULL;
     }
 
     u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t));
@@ -2834,6 +2835,7 @@ ngx_http_upstream_finalize_request(ngx_http_request_t *r,
 
     if (u->cleanup) {
         *u->cleanup = NULL;
+        u->cleanup = NULL;
     }
 
     if (u->state && u->state->response_sec) {