0

nginxの設定でhttps上のファイル名を書き換えるにはどうすればいいですか?

たとえば、私は

/public/abc.html /public/abc-s.html

https://mydomain/abc.htmlしかし、 loadabc-s.html中にhttp://mydomain/abc-s.htmlloadにアクセスするユーザーが必要ですabc.html

どうも

4

1 に答える 1

0

これは、一連の正規表現によって実行できます。例:

  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 でテスト済み。

于 2013-07-08T18:26:13.907 に答える