讓Nginx路徑中的子目錄匹配文件夾的另外一種寫法

其實至關於對路徑作一種通配符,根據路徑名訪問相應的文件夾。直接看高潮部分以下。。html

location /static {
        root /var/www/usmt;
        index index.html board.html 03-multiple-grids.html;
        set $real_script '';
        if ( $fastcgi_script_name ~ /static(.*) ){  # 根據location的匹配規則,$1不會爲空
            set $real_script $1;
        }
        # 訪問時會把截取的地址拼接上location的字符串
        try_files $real_script $real_script/;
    }

訪問static時,返回static文件夾的內容;訪問staticxxx文件夾時,返回staticxxx文件夾下的內容。code

相關文章
相關標籤/搜索