I want to handle all [GET] requests to /api from cache and handle all other requests as in last location block (without cache). All the requests to /api with methods PUT, POST, DELETE also have not to use cache.
I saw the similar question here Nginx proxy by Request Method, but still can not understand how to use it in my case.
Thanks in advance.
My config:
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;
}
Best Answer
Here my question was answered stackoverflow.com/a/35291314/1517230 by clever stackoverflow users :)
or