Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

How can I write an nginx location directive that matches the url /%ef?

$
0
0
I want to match a request like GET /%ef HTTP/1.1. So I created this configuration:

location /%ef {
return 400;
}
I compiled nginx with debug, and did curl -v 'localhost:8080/%ef'. I got 404 instead of my expected 400. Here is the relevant part of the log:

2015/03/29 17:40:43 [debug] 48043#0: *5 http request line: "GET /%ef HTTP/1.1"
2015/03/29 17:40:43 [debug] 48043#0: *5 s:0 in:'2F:/'
2015/03/29 17:40:43 [debug] 48043#0: *5 s:1 in:'25:%'
2015/03/29 17:40:43 [debug] 48043#0: *5 s:4 in:'65:e'
2015/03/29 17:40:43 [debug] 48043#0: *5 s:5 in:'66:f'
2015/03/29 17:40:43 [debug] 48043#0: *5 s:1 in:'EF:ï'
2015/03/29 17:40:43 [debug] 48043#0: *5 http uri: "/ï"
2015/03/29 17:40:43 [debug] 48043#0: *5 http args: ""
2015/03/29 17:40:43 [debug] 48043#0: *5 http exten: ""
2015/03/29 17:40:43 [debug] 48043#0: *5 http process request header line
2015/03/29 17:40:43 [debug] 48043#0: *5 http header: "User-Agent: curl/7.37.1"
2015/03/29 17:40:43 [debug] 48043#0: *5 http header: "Host: localhost:8080"
2015/03/29 17:40:43 [debug] 48043#0: *5 http header: "Accept: */*"
2015/03/29 17:40:43 [debug] 48043#0: *5 http header done
2015/03/29 17:40:43 [debug] 48043#0: *5 event timer del: 4: 1427676103018
2015/03/29 17:40:43 [debug] 48043#0: *5 rewrite phase: 0
2015/03/29 17:40:43 [debug] 48043#0: *5 test location: "/"
2015/03/29 17:40:43 [debug] 48043#0: *5 test location: "50x.html"
2015/03/29 17:40:43 [debug] 48043#0: *5 using configuration "/"
So it looks like based on the line 2015/03/29 17:40:43 [debug] 48043#0: *5 http uri: "/ï", nginx is matching this request to /ï, which is what %ef is when url-decoded. OK. I updated the configuration like this:

location /%ef {
return 400;
}
location /ï {
return 400;
}
I repeated my request. Now I get:

2015/03/29 17:37:48 [debug] 48018#0: *4 http request line: "GET /%ef HTTP/1.1"
2015/03/29 17:37:48 [debug] 48018#0: *4 s:0 in:'2F:/'
2015/03/29 17:37:48 [debug] 48018#0: *4 s:1 in:'25:%'
2015/03/29 17:37:48 [debug] 48018#0: *4 s:4 in:'65:e'
2015/03/29 17:37:48 [debug] 48018#0: *4 s:5 in:'66:f'
2015/03/29 17:37:48 [debug] 48018#0: *4 s:1 in:'EF:ï'
2015/03/29 17:37:48 [debug] 48018#0: *4 http uri: "/ï"
2015/03/29 17:37:48 [debug] 48018#0: *4 http args: ""
2015/03/29 17:37:48 [debug] 48018#0: *4 http exten: ""
2015/03/29 17:37:48 [debug] 48018#0: *4 http process request header line
2015/03/29 17:37:48 [debug] 48018#0: *4 http header: "User-Agent: curl/7.37.1"
2015/03/29 17:37:48 [debug] 48018#0: *4 http header: "Host: localhost:8080"
2015/03/29 17:37:48 [debug] 48018#0: *4 http header: "Accept: */*"
2015/03/29 17:37:48 [debug] 48018#0: *4 http header done
2015/03/29 17:37:48 [debug] 48018#0: *4 event timer del: 3: 1427675928222
2015/03/29 17:37:48 [debug] 48018#0: *4 rewrite phase: 0
2015/03/29 17:37:48 [debug] 48018#0: *4 test location: "/"
2015/03/29 17:37:48 [debug] 48018#0: *4 test location: "50x.html"
2015/03/29 17:37:48 [debug] 48018#0: *4 test location: "ï"
2015/03/29 17:37:48 [debug] 48018#0: *4 using configuration "/"
It is still not matching my locations. And based on the line 2015/03/29 17:37:48 [debug] 48018#0: *4 test location: "ï", it seems like my new location is being interpreted in an unexpected way.

How can I write a location directive that matches the url /%ef?

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>