2017-08-10 4 views
1

CSS、JSなどに関して/ var/www/acmeに適用されるルールが/ var/www/acmeに適用されないように、Webサーバー上でNGINXルールの特別なディレクトリの上書きが必要です/特別。 me.com(127.0.0.1 localhost setup)の下に私のウェブサイトを含む/ var/wwwがあります。そこには、私のPHP用の特別なフレームワークを使用するacmeフォルダがあります。しかし、私は/ var/www/acme/specialというフォルダを用意しています。これらは同じ規則を適用せず、通常のPHP Webサイトと同じように実行する必要があります。/var/www/acme/specialのための特別な場所とtry_filesルーチンと、休憩と一緒にロジックを適用すると、内部的にリライトまたは内部リダイレクションサイクルと呼ばれるHTTP 500エラーが発生するため、 '/ acme/special //////////////'にリダイレクトされます。NGINXでディレクトリオーバーライド

私の/etc/nginx/sites-available/me.comファイルは、Ubuntu 16.04のNGINX用です。私は間違って何をしていますか?

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は、書き換えモジュールの一部であり、ここでは目的がありません。

関連する問題