티스토리 뷰

Developer

[nginx] 자동 urldecoding문제

rocksea 2013. 8. 22. 16:32

자동 urldecoding 문제

client에서 urlencoding되어 넘어온 변수가  WAS에 도달시 자동으로 decoding 되어

있는 문제가 있어 추적해보니 nginx 에서 proxy_pass할때 자동으로 decoding을 

하게 된다는 것을 알게 되었다.

예를들어

bar%2Fbaz -> /foo/bar/baz로 decoding되어 WAS로 넘어오게 되어 WAS에서 url mapping을 할 수가 없는 상황.

이유를 찾아보니 아주 단순했다.


-     proxy_pass http://backend/;

+        proxy_pass http://backend; 


location / {

         proxy_pass http://backend;

}


뒤에 슬러시가 붙어 있었기 때문이었다.

아래처럼 설정해주면 encoding된 그상태로 proxy_pass를 할 수 있다.

반대로 decoding된 상태로 WAS로 전달 할 경우 반대로 슬러시를 붙여주면 된다.


location / {

         proxy_pass http://backend/;

}

사소한것 같지만 알아두면 좋을 듯 싶다.

댓글