Sunday, January 11, 2015

Why does nginx remove a / in the URL?



We use nginx as proxy for our play framework 1.2.7 server. Some of the routes in play framework use a <.*> wildcard, the one in question here looks like




GET     /media/{bucket}/{id}/inline/{<.*>config}    MediaCtl.getMediaInlineImgIx


The config can contain a http server and for some reason nginx strips away one of the / in http:// . For example:



13:07:59,299 INFO  [play] ~ Anonymous Guest ~ MediaCtl.getImgIx(): config {"w":100,"h":65,"origin":"http:/localhost:8080","fit":"max"}


when using nginx via localhost:8080. When calling localhost:9010 directly I get




13:19:25,648 INFO  [play] ~ Anonymous Guest ~ MediaCtl.getImgIx(): config {"w":100,"h":65,"origin":"http://localhost:9010","fit":"max"}


I see no messages in access.log or error.log with regards to the URL mangling that seems to occur. Any suggestions on how to fix this?


Answer



nginx merges slashes from URLs on default
see: http://nginx.org/en/docs/http/ngx_http_core_module.html#merge_slashes



You must use: merge_slashes off;


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...