2017-02-03 5 views
0

私は以下を欲しいです。 http://some.site/person1/some/path/home/person1/some/pathにアクセスする(及びhttp://some.site/person1/home/person1/index.htmlにアクセス)とhttp://some.site/person2/some/path/home/person2/some/pathにアクセスしなければならない(及びhttp://some.site/person2/home/person2/index.htmlにアクセスする)べきです。 personXが多数あります。 nginxにすべてを見つける場所を伝えるには、正規表現を使用することが重要です。nginx:ルートに基づいて選択されたルート

私は、動作するルート、リライトディレクティブのセットを試してみました。私が一番近かったのは私のsites-available/websiteでした。

server { 
     listen 80 default_server; 
     listen [::]:80 default_server; 
     server_name _; 
     root /some/default/root; 

     # Add index.php to the list if you are using PHP 
     index index.html index.htm index.nginx-debian.html; 

     location/{ 
       # First attempt to serve request as file, then 
       # as directory, then fall back to displaying a 404. 
       try_files $uri.html $uri $uri/ =404; 
     } 

     location /person1 { 
       root /home/person1; 
       rewrite ^/person1(.*)$ $1 break; 
     } 
} 

これは、フォームhttp://some.site/person1以外のすべてのパスで必要なものです。この場合、nginxは私が望むように/home/person1/index.htmlにアクセスしません。代わりに、正規表現は、nginxが好きではない空の文字列を返します(nginx/error.logに苦情があります)。

答えて

0

あなたが/自宅共通スタートのルートディレクトリを持っている場合、あなたが試すことができます:

location ~* /person\d+ { 
    root /home; 
} 
関連する問題