Nginx displays a peculiar but logical behavior when handling directories specified without the ending slash. For example you have a directory like http://www.example2.com/dir/. However you specify the url as http://www.example2.com/dir. Also assume that you have configured the server for virtual hosting and the alternative server names are: www.example.com, www.example2.com etc. and they are specified in the same order. Now when you try to fetch http://www.example2.com/dir you will instead be redirected to http://www.example.com/dir. Here is why nginx does it along with a simple solution to the rather baffling problem (ok complex problem - I said it).

Full article (275 words) »