I need to translate the address:
www.example.com/TEST in ---> www.example.com/test
はい、perl が必要になります。Ubuntu を使用している場合は、apt-get install nginx-full の代わりに、perl モジュールが組み込まれた apt-get install nginx-extras を使用します。次に、構成ファイルで次のようにします。
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;
}
...
location /dupa/ {
set_by_lua $request_uri_low "return ngx.arg[1]:lower()" $request_uri;
rewrite ^ https://$host$request_uri_low;
}
私は埋め込まれたperlを使用して目標を達成することができました:
location ~ [A-Z] {
perl 'sub { my $r = shift; $r->internal_redirect(lc($r->uri)); }';
}
location ~*^/test/ {
return 301 http://www.example.com/test;
}
場所は、プレフィックス文字列または正規表現のいずれかで定義できます。正規表現は、前に「~*」修飾子 (大文字と小文字を区別しない一致)または「~」修飾子 (大文字と小文字を区別する一致) を付けて指定します。
ソース: http://nginx.org/en/docs/http/ngx_http_core_module.html#location