Welcome! Log In Create A New Profile

Advanced

rewrite / proxy_pass different bahaviour in 1.0 and 1.2

September 28, 2012 11:36AM
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.
Subject Author Posted

rewrite / proxy_pass different bahaviour in 1.0 and 1.2

alexey.radkov September 28, 2012 11:36AM

Re: rewrite / proxy_pass different bahaviour in 1.0 and 1.2

Maxim Dounin September 28, 2012 02:00PM

Re: rewrite / proxy_pass different bahaviour in 1.0 and 1.2

alexey.radkov September 29, 2012 09:33AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 261
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready