2017-08-10 97 views
1

我需要在我的Web服務器上使用NGINX規則的特殊目錄覆蓋,以便適用於/ var/www/acme的關於CSS,JS等的規則不適用於/ var/www/acme /特別。我有一個/ var/www包含me.com下的我的網站(127.0.0.1本地主機設置)。在那裏,我有一個acme文件夾,它爲我的PHP使用了一個特殊的框架。不過,我有一個文件夾/ var/www/acme/special,它不需要應用這些相同的規則,而只需像普通的PHP網站一樣運行。我被卡住了,因爲當我使用特殊位置的邏輯和try_files例程以及/ var/www/acme/special中斷時,我得到一個HTTP 500錯誤,指出「在內部重寫或內部重定向循環重定向到'/ acme/special ////////////「。NGINX的目錄覆蓋

這是我在Ubuntu 16.04上的NGINX的/etc/nginx/sites-available/me.com文件。我究竟做錯了什麼?

server { 

    listen 80; 
    listen [::]:80; 

    root /var/www; 

    index index.php index.html; 

    server_name me.com www.me.com; 


    location /acme/special { 
     try_files $uri $uri/; 
     break; 
    } 

    location ~ ^/acme/(.*(?<!boot))/css/(.*)$ { 
     alias /var/www/acme/$1/views/assets/css/$2; 
    } 

    location ~ ^/acme/(.*(?<!boot))/js/(.*)$ { 
     alias /var/www/acme/$1/views/assets/js/$2; 
    } 

    location ~ ^/acme/(.*(?<!boot))/img/(.*)$ { 
     alias /var/www/acme/$1/views/assets/img/$2; 
    } 

    location ~ ^/acme/(.*)/fonts/(.*(?<!boot))$ { 
     alias /var/www/acme/$1/views/assets/fonts/$2; 
    } 

    location ~ ^/acme/(.*)/boot/(.*)$ { 
     alias /var/www/acme/$1/views/assets/boot/$2; 
    } 

    location/{ 
     try_files $uri $uri/ @php; 
    } 

    location @php { 
     rewrite ^/acme/([^\/]+)/.*((?!index\.php).)*$ /acme/$1/index.php?query_string last; 
    } 

    location ~ \.php$ { 
     include snippets/fastcgi-php.conf; 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    } 


} 

回答

0

嘗試:

location /acme/special { 
    try_files $uri $uri/ =404; 
} 

try_files聲明的最後一個參數是默認操作,所以$uri/長期不被視爲文件詞彙之一。使用=404或類似/index.php取決於您所需的文件未找到的響應。有關更多信息,請參見this document

break是重寫模塊的一部分,在這裏沒有用處。