2

nginxを使用してファイルサーバーを開発しています。サーバー ファイルにアクセスするには、各ディレクトリの後に文字列を追加する必要があります。

例: 私の URL は

http://desk09/1.2/junior/kal12/pnr.doc

これを次の名前のローカルファイルに変更する必要があります

../junior@1.2/kal12@1.2/pnr.doc

以下のようなnginx構成ファイルのみを使用して実行できますか:

location ~ "^/([1-9]{1}\.[0-9]{1}/(.*)" {
    root /usr/home/fs/......
}
4

1 に答える 1

0

答えを変更して、再帰的に機能させるようにします。

最初に最初からバージョン番号をスローし、これを最初のディレクトリに追加します

location ~ "^/([0-9]{1}\.[0-9]{1})/([a-zA-Z0-9]+)/(.*\.doc)$" {
    rewrite     .*  /$2@$1/$3;
}

だから今URL:

/1.2/junior/many_sub_dir_here/test.doc    ->   /junior@1.2/many_sub_dir_here/test.doc

これlocationで、ディレクティブ belove が再帰的な場所として機能します (再帰的な場所の呼び出しを許可するように nginx をマークします):

location ~ "^(/[a-zA-Z0-9]+@)([0-9]{1}\.[0-9]{1})/(([a-zA-Z0-9]+@[0-9]{1}\.[0-9]{1}/)*)([a-zA-Z0-9]+)/(.*\.doc)$" {
    rewrite .* /$1$2/$3$5@$2/$6;        
}

あなたのURLの場合、次のように機能します

/junior@1.2/x1/x2/x3/test.doc           -->   /junior@1.2/x1@1.2/x2/x3/test.doc
  $1 = /junior@
  $2 = 1.2
  $3 = 
  $4 = 
  $5 = x1
  $6 = x2/x3/test.doc

/junior@1.2/x1@1.2/x2/x3/test.doc       -->   /junior@1.2/x1@1.2/x2@1.2/x3/test.doc
  $1 = /junior
  $2 = 1.2
  $3 = x1@1.2/
  $4 = x1@1.2/
  $5 = x2
  $6 = x3/text.doc

/junior@1.2/x1@1.2/x2@1.2/x3/test.doc   -->   /junior@1.2/x1@1.2/x2@1.2/x3@1.2/test.doc
  $1 = /junior@
  $2 = 1.2
  $3 = x1@1.2/x2@1.2/
  $4 = x2@1.2/
  $5 = x3
  $6 = test.doc

この最後の URL は上記のブロックの正規表現と一致しなくなるlocationため、ここでは次のような最終的なロケーション ブロックを使用します。

location ~ ".*(@[0-9]{1}\.[0-9]{1})/[^@/]+\.doc$" {
    root root /usr/home/fs;
    try_files $uri =404;
}
于 2013-01-29T12:33:16.117 に答える