我在serverfault上提出了这个问题,但是没有人回答。希望stackoverflow的人更了解Nginx :)
我想要将所有对/api的[GET]请求都处理为缓存,并将所有其他请求处理为最后一个位置块中的内容(不使用缓存)。所有使用PUT、POST、DELETE方法的/api请求也不能使用缓存。
我看到了类似的问题here,但仍然不知道如何在我的情况下使用它。
先谢谢了。
我的配置:
location / {
root /var/www/project/web;
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location ~ ^/api {
root /var/www/project/web/app.php;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/?.*)$;
include fastcgi_params;
fastcgi_cache fcgi;
fastcgi_cache_valid 200 5m;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
location ~ ^/(app|app_dev|config)\.php(/|$) {
root /var/www/project/web;
fastcgi_send_timeout 600s;
fastcgi_read_timeout 600s;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/?.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}