我想检查文件是否存在于自定义位置(根目录之外)强制提供此文件,否则重写 index.php
文件位置取决于子域和 URL 路径:
网址:http://my.subdomain.mysite.com/location/of/file.css
文件路径:/tmp/cache/my.subdomain/location/of/file.css
我的网站可用:
server {
listen 80;
server_name mysite.com ~([\w\.]+)\.mysite\.com$ ;
set $subdomain $1;
root /var/www/site/web;
index index.php index.html;
location / {
set $cacheDir /tmp/cache;
set $cacheFile "${cacheDir}/${subdomain}/${request_uri}";
if (-f $cacheFile) {
?????
????? what do I write here?
?????
}
include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
.
.
.
}
}
答案1
如果你真的想这样做,那就试试吧
location / {
set $cacheDir /tmp/cache;
set $cacheFile "${cacheDir}/${subdomain}${uri}";
if (-f $cacheFile) {
root "${cacheDir}/${subdomain}";
}
}
location ~ \.php$ {
# your fastcgi config here
}
请注意,nginx 对 /tmp/cache 的访问可能会被默认的 SELinux 策略阻止。