我正在使用不同的根path/cloud但每当我尝试请求任何/cloud/*.php文件nginx说404文件未find。 我可以访问/cloud/*.html没有任何问题。 我甚至可以访问任何/*.php但不知道/cloud 。 我的configuration文件看起来像
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html index.php; server_name _; location /cloud { root /home/fhost/public_html; } location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php7.0-fpm.sock; } location ~ /\.ht { deny all; } }
使用两个根的PHP,你将需要一个location块为每个。 最干净的解决scheme是位于块location ^~ /cloud内的嵌套位置块。 请注意,使用^~修饰符使得这个前缀location优先于其他location ~ \.php$ block。 请参阅此文档了解更多
location ^~ /cloud { root /home/fhost/public_html; location ~ \.php$ { ... } }