nginxの設定でhttps上のファイル名を書き換えるにはどうすればいいですか?
たとえば、私は
/public/abc.html /public/abc-s.html
https://mydomain/abc.html
しかし、 loadabc-s.html
中にhttp://mydomain/abc-s.html
loadにアクセスするユーザーが必要ですabc.html
。
どうも
これは、一連の正規表現によって実行できます。例:
set $hasdashs u; # if we don't match .html we don't want to do a rewrite
if ($uri ~* "^(.*)\.html$") { # are we looking at a .html page? If so, get the base name
set $hasdashs n;
set $shorturi "$1";
}
if ($uri ~ "^(.*)-s\.html$") { # are we looking at a secure page? Get the base name without -s
set $hasdashs y;
set $shorturi "$1";
}
set $schemecheck "$scheme$hasdashs";
if ($schemecheck = "httpy") { #we're using http and looking at a secure page
rewrite . "${shorturi}.html" redirect;
}
if ($schemecheck = "httpsn") { #we're using https and looking at an insecure page
rewrite . "${shorturi}-s.html" redirect;
}
これは、構成のロケーション ブロックではなく、サーバー ブロックにある必要があることに注意してください。NGINX 1.2.1 でテスト済み。