ðòïåëôù 


  áòèé÷ 


Apache-Talk @lexa.ru 

Inet-Admins @info.east.ru 

Filmscanners @halftone.co.uk 

Security-alerts @yandex-team.ru 

nginx-ru @sysoev.ru 


  óôáôøé 


  ðåòóïîáìøîïå 


  ðòïçòáííù 



ðéûéôå
ðéóøíá












     áòèé÷ :: nginx-ru
Nginx-ru mailing list archive (nginx-ru@sysoev.ru)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

rewrite / proxy_pass different bahaviour in 1.0 and 1.2


  • To: nginx-ru@xxxxxxxxx
  • Subject: rewrite / proxy_pass different bahaviour in 1.0 and 1.2
  • From: "alexey.radkov" <nginx-forum@xxxxxxxx>
  • Date: Fri, 28 Sep 2012 11:36:49 -0400
  • Dkim-signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tigger.jlkhosting.com; s=x; h=Date:Sender:From:Message-ID:Content-Transfer-Encoding:Content-Type:Subject:To; bh=qw/Fp3+HpHNtBXCC9W9omsbvqUoqJ9cWpiIQCQfW9eY=; b=sHYqA50yKqAp6IjEQtgEV73NsHqnrbe77sth52cvHauFCoLJG5an7O8WMUCAOg00cG1CLMerkhVzr7X4hYam1gk8RIe8KZou29I+H+78vRwFy3Z+QBw4buLK20wa8eLk;

Hi guys.


Is the following result of a bug fix in proxy module in 1.2 series?

Imagine following config (sorry, i do not know how to format it here):


events {
    worker_connections  1024;
}

http {
    upstream ubackend {
        server localhost:8020;
    }

    server {
        listen          8010;
        server_name     router;

        location /test.html {
            rewrite ^ /Internal_test last;
        }

        location /Internal_test {
            internal;
            proxy_pass http://$arg_a;
        }
    }

    server {
        listen          8020;
        server_name     backend;

        location /test.html {
            echo "In backend";
        }
    }
}



and following request:

curl 'http://localhost:8010/test.html?a=ubackend'

Then 1.0 behaviour:


In backend


1.2 behaviour:


<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.2.3</center>
</body>
</html>



ngrep traces:

1.0:

#####
U 127.0.0.1:36906 -> 127.0.0.1:36906
.
######
T 127.0.0.1:44685 -> 127.0.0.1:8010 [AP]
GET /test.html?a=ubackend HTTP/1.1.
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0
NSS/3.13.5.0 zlib/1.2.5 libidn/1.24 libssh2/1.4.1.
Host: localhost:8010.
Accept: */*.
.

#####
T 127.0.0.1:39418 -> 127.0.0.1:8020 [AP]
GET /test.html?a=ubackend HTTP/1.0.
Host: ubackend.
Connection: close.
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0
NSS/3.13.5.0 zlib/1.2.5 libidn/1.24 libssh2/1.4.1.
Accept: */*.
.

##
T 127.0.0.1:8020 -> 127.0.0.1:39418 [AP]
HTTP/1.1 200 OK.
Server: nginx/1.0.10.
Date: Fri, 28 Sep 2012 15:07:55 GMT.
Content-Type: text/html.
Content-Length: 11.
Connection: close.
.
In backend

#####
T 127.0.0.1:8010 -> 127.0.0.1:44685 [AP]
HTTP/1.1 200 OK.
Server: nginx/1.0.10.
Date: Fri, 28 Sep 2012 15:07:55 GMT.
Content-Type: text/html.
Connection: keep-alive.
Content-Length: 11.
.
In backend


1.2 :

#
U 127.0.0.1:36906 -> 127.0.0.1:36906
.
######
T 127.0.0.1:44696 -> 127.0.0.1:8010 [AP]
GET /test.html?a=ubackend HTTP/1.1.
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0
NSS/3.13.5.0 zlib/1.2.5 libidn/1.24 libssh2/1.4.1.
Host: localhost:8010.
Accept: */*.
.

#####
T 127.0.0.1:39429 -> 127.0.0.1:8020 [AP]
GET /Internal_test?a=ubackend HTTP/1.0.
Host: ubackend.
Connection: close.
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0
NSS/3.13.5.0 zlib/1.2.5 libidn/1.24 libssh2/1.4.1.
Accept: */*.
.

##
T 127.0.0.1:8020 -> 127.0.0.1:39429 [AP]
HTTP/1.1 404 Not Found.
Server: nginx/1.2.3.
Date: Fri, 28 Sep 2012 15:08:51 GMT.
Content-Type: text/html.
Content-Length: 168.
Connection: close.
.
<html>.
<head><title>404 Not Found</title></head>.
<body bgcolor="white">.
<center><h1>404 Not Found</h1></center>.
<hr><center>nginx/1.2.3</center>.
</body>.
</html>.

#####
T 127.0.0.1:8010 -> 127.0.0.1:44696 [AP]
HTTP/1.1 404 Not Found.
Server: nginx/1.2.3.
Date: Fri, 28 Sep 2012 15:08:51 GMT.
Content-Type: text/html.
Content-Length: 168.
Connection: keep-alive.
.
<html>.
<head><title>404 Not Found</title></head>.
<body bgcolor="white">.
<center><h1>404 Not Found</h1></center>.
<hr><center>nginx/1.2.3</center>.
</body>.
</html>.



So the difference is that in 1.0 original URI is not rewritten in HTTP GET
header when proxied after rewrite, but in 1.2 it is rewritten to
/Internal_test thus giving result 404 Not Found.


Do I understand this right that 1.0 behaviour was not correct and just fixed
in 1.2?


To achieve 1.0 behaviour in 1.2 i can add only 2 lines of code from 1.0.
Here is diff:


--- ngx_http_proxy_module.c     2012-09-28 19:16:42.416144040 +0400
+++ ngx_http_proxy_module.c.new 2012-09-28 19:16:33.505015157 +0400
@@ -783,10 +783,13 @@
             ngx_memcpy(p, url.uri.data, url.uri.len);
 
             url.uri.len++;
             url.uri.data = p - 1;
         }
+
+    } else {
+        url.uri = r->unparsed_uri;
     }
 
     ctx->vars.key_start = u->schema;
 
     ngx_http_proxy_set_vars(&url, &ctx->vars);


Cheers, Alexey.

Posted at Nginx Forum: 
http://forum.nginx.org/read.php?21,231218,231218#msg-231218

_______________________________________________
nginx-ru mailing list
nginx-ru@xxxxxxxxx
http://mailman.nginx.org/mailman/listinfo/nginx-ru


 




Copyright © Lexa Software, 1996-2009.