Nginx: how to save double slashes in urls

I have a web service that accepts several filter parameters, for example:

http://mydomain.com/filter1/value1/filter2/value2/filter3/value3

The difficulty is that sometimes some of the filter variables are missing, so URLs can be passed to this service:

http://mydomain.com/filter1//filter2//filter3/value3

Now I need to configure my nginx (or fastcgi) to save double slashes. Currently, it is replacing double slashes with single slashes. I am new to nginx and fastcgi settings and I don't know how to do this. I grabbed request_uri from my php script when I asked for a second url and I got

http://mydomain.com/filter1/filter2/filter3/value3

Help me. Thanks in advance.

+8
source share
5 answers
syntax: merge_slashes [on|off]
default: merge_slashes on
context: http, server

You should use merge_slashes off:;

+21
source

nginx + ( Ruby on Rails/Rack/ ..), , ( PATH_INFO, REQUEST_URI).

merge_slashes off; server nginx ( ).

+5

, , proxy_pass!

  • : proxy_pass http://localhost:3000;

  • BAD: proxy_pass http://localhost:3000/;

+3

, merge_slashes off; Nginx. , , , . v1.4.1 v1.4.6.

0

, , ,

      proxy_redirect     default;
      proxy_http_version 1.1;
      proxy_set_header   Host              $host;
      proxy_set_header   X-Real-IP         $remote_addr;
      proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
      proxy_set_header   X-Forwarded-Proto $scheme;
      proxy_max_temp_file_size 0;

: nginx

0

All Articles