Thi*_*lli 15

是的,你将需要perl.如果您使用的是Ubuntu,而不是apt-get install nginx-full,请使用apt-get install nginx-extras,它将具有嵌入式perl模块.然后,在您的配置文件中:

  http {
  ...
    # Include the perl module
    perl_modules perl/lib;
    ...
    # Define this function
    perl_set $uri_lowercase 'sub {
      my $r = shift;
      my $uri = $r->uri;
      $uri = lc($uri);
      return $uri;
    }';
    ...
    server {
    ...
      # As your first location entry, tell nginx to rewrite your uri,
      # if the path contains uppercase characters
      location ~ [A-Z] {
        rewrite ^(.*)$ $scheme://$host$uri_lowercase;
      }
    ...
Run Code Online (Sandbox Code Playgroud)


Ada*_*awy 9

location /dupa/ {
    set_by_lua $request_uri_low "return ngx.arg[1]:lower()" $request_uri;
    rewrite ^ https://$host$request_uri_low;
}
Run Code Online (Sandbox Code Playgroud)


Den*_*nik 8

我设法使用嵌入式perl实现目标:

location ~ [A-Z] {
  perl 'sub { my $r = shift; $r->internal_redirect(lc($r->uri)); }';
}
Run Code Online (Sandbox Code Playgroud)