Re: rewrite при переходе 0.2.4 - 0.3.7

Igor Sysoev is at rambler-co.ru
Mon Nov 7 17:59:31 MSK 2005


On Mon, 7 Nov 2005, Alexander Kuzmin wrote:

> При смене версий 0.2.4 -> 0.3.7 следующая конструкция перестала
> работать ("connection was refused while contact http://127.0.0.1")
>
> nginx.conf:
>
> ...
> location ~ ^/news/([0-9]+)\.html$ {
> rewrite ^/news/([0-9]+)\.html$ /news.php?n_id_news=$1 last;
> }
> ...
> location ~ ^.+\.php$ {
> proxy_pass  http://127.0.0.1;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_redirect off;
> proxy_pass_request_headers on;
> proxy_pass_request_body on;
> }
> ...
>
> Заработало при изменении первого location следующим образом:
>
> location ~ ^/news/([0-9]+)\.html$ {
> rewrite ^/news/([0-9]+)\.html$ /news.php?n_id_news=$1 break;
> proxy_pass  http://127.0.0.1;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_pass_request_headers on;
> proxy_pass_request_body on;
> }
>
> Просмотр рассылки и доки на сей предмет ничего не дал.
>
> Чем вызвана такая ситуация? Я где-то что-то пропустил?
> Не хотелось бы дублировать конфиги...

Насколько я вижу в отладочном логе, там проблема не с connection was refused,
а с тем, что бэкенду передаются запрос:
"GET ??n_id_news=XXXXX HTTP/1.0"

Прилагаемывй патч должен решить эту пробему.


Игорь Сысоев
http://sysoev.ru
-------------- next part --------------
--- src/http/ngx_http_upstream.h	Fri Oct 21 23:47:15 2005
+++ src/http/ngx_http_upstream.h	Mon Nov  7 17:50:24 2005
@@ -83,7 +83,7 @@
 
     ngx_str_t                       schema;
     ngx_str_t                       uri;
-    ngx_str_t                      *location;
+    ngx_str_t                       location;
     ngx_str_t                       url;  /* used in proxy_rewrite_location */
 } ngx_http_upstream_conf_t;
 
--- src/http/modules/ngx_http_proxy_module.c	Thu Nov  3 19:54:20 2005
+++ src/http/modules/ngx_http_proxy_module.c	Mon Nov  7 17:51:40 2005
@@ -431,7 +432,7 @@
 
     escape = 0;
 
-    loc_len = r->valid_location ? u->conf->location->len : 0;
+    loc_len = r->valid_location ? u->conf->location.len : 0;
 
     if (u->conf->uri.len == 0 && r->valid_unparsed_uri) {
         len += r->unparsed_uri.len;
@@ -1523,7 +1525,7 @@
 
             pr->handler = ngx_http_proxy_rewrite_redirect_text;
             pr->redirect = conf->upstream.url;
-            pr->replacement.text = *conf->upstream.location;
+            pr->replacement.text = conf->upstream.location;
         }
     }
 
@@ -1836,15 +1840,19 @@
 
     clcf->handler = ngx_http_proxy_handler;
 
-    plcf->upstream.location = &clcf->name;
+    plcf->upstream.location = clcf->name;
 
 #if (NGX_PCRE)
 
-    if (clcf->regex && plcf->upstream.uri.len) {
-        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
-                           "\"proxy_pass\" may not have URI part in "
-                           "location given by regular expression");
-        return NGX_CONF_ERROR;
+    if (clcf->regex) {
+        if (plcf->upstream.uri.len) {
+            ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                               "\"proxy_pass\" may not have URI part in "
+                               "location given by regular expression");
+            return NGX_CONF_ERROR;
+        }
+
+        plcf->upstream.location.len = 0;
     }
 
 #endif
@@ -1904,7 +1912,7 @@
 
         pr->handler = ngx_http_proxy_rewrite_redirect_text;
         pr->redirect = plcf->upstream.url;
-        pr->replacement.text = *plcf->upstream.location;
+        pr->replacement.text = plcf->upstream.location;
 
         return NGX_CONF_OK;
     }
--- src/http/modules/ngx_http_fastcgi_module.c	Thu Nov  3 18:29:03 2005
+++ src/http/modules/ngx_http_fastcgi_module.c	Mon Nov  7 17:51:49 2005
@@ -1858,7 +1864,7 @@
 
     clcf->handler = ngx_http_fastcgi_handler;
 
-    lcf->upstream.location = &clcf->name;
+    lcf->upstream.location = clcf->name;
 
     if (clcf->name.data[clcf->name.len - 1] == '/') {
         clcf->auto_redirect = 1;


More information about the nginx-ru mailing list