2017-08-09 98 views
0

我在this question中發現誰將$ request_uri的第一個目錄映射到nginx變量。

我需要做的是白衣2個目錄和一個文件:本地主機:80/DIR1/DIR2/file.html地圖爲localhost:80/$ TOPDIR/$ secondir/$文件

我做的:

map $request_uri $topdir { 
    ~(?<captured_topdir>[^\/]*[^\/]) $captured_topdir; 
} 
map $request_uri $secondir{ 
    ~([^\/]?<secondir>[^\/]) $secondir; 
} 
map $request_uri $endpart { 
    ~([^\/]*[^\/]?<endpart>) $endpart; 
} 

但沒有運氣,當我在nginx上試用它時,只有$ topdir工作正常!

謝謝!

回答

0

我finnaly以不同的方式解決這個問題,沒有地圖。剛剛在我使用的位置

 if ($request_uri ~ "^(.*)/(.*)/(.*).*$") { 
      set $first $1; 
      set $second $2; 
      set $third $3; 
     } 

然後現在,$第一,$第二和$第三有每個部分。