Nginx Cache For Yii Project

have such nginx configuration, but cache not working, no file in folder /var/cache/nginx and all responses is 200. What to fix? I tried differend variationts without any result.

fastcgi_cache_path /var/cache/nginx/ levels=2 keys_zone=workfolder:10m max_size=512m inactive=20m;

server {

                    listen 80;

                    client_max_body_size 10m;

                    client_header_buffer_size 4k;

                    access_log /srv/logs/site-access.log;

                    error_log /srv/logs/site-error.log;

                    root /srv/www/Site;

                    server_tokens off;

                    server_name_in_redirect off;

                    charset utf-8;

                    fastcgi_intercept_errors on;

                    #index index.php index.html index.htm;

                    fastcgi_pass_header Cookie;

                    fastcgi_cache wahoos;

                    fastcgi_cache_key $request_method|$host|$request_uri;

                    fastcgi_cache_valid 301 8h;

                    fastcgi_cache_valid 404 1h;

                    fastcgi_cache_valid 200 15m;

                    location / {

                            index index.php index.html index.htm;

                            try_files $uri $uri/ /index.php?$args;


                    location @php {

                            include /etc/nginx/fastcgi_params;

                            fastcgi_param SCRIPT_FILENAME /srv/www/Site/index.php;


                    location /api {

                            fastcgi_cache off;


                    location ~ \.(css|js|txt|jpg|jpeg|png)$


                        access_log off;

                        expires 1d;

                        add_header Pragma public;

                        add_header Cache-Control private;



I dont think that its about yii…

i saw your post on stackoverflow but i dont have any idea…

Yea, i know, but maybe smbd can share their ideas :)

[color="#006400"]/* Moved from "General Discussion for Yii 1.1.x" to "Miscellaneous" */[/color]

Is there a fastcgi_cache_path directive configured in your http block?

yes, i tried to put in http section and common, no results

common? What is common? Anyway, could you hsow us the aforementioned directive?


user              nginx;

worker_processes  2;

error_log  /srv/logs/nginx-error.log;

pid        /var/run/;

events {

    worker_connections  1024;


http {

   include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

    client_max_body_size 50m;

        log_format  main  '$remote_addr - [$time_local] "$host" "$request" '

                      '$status ($bytes_sent) "$http_referer" '

                      '"$uri $args" [$request_time]'


    access_log  /srv/logs/nginx-access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    fastcgi_cache_path /var/cache/nginx/ levels=1:2 keys_zone=nginx_webpy_cache:1m inactive=1d;

fastcgi_temp_path /var/cache/nginx/temp;

fastcgi_cache_key "$scheme$request_method$host$request_uri$is_args$args";

    gzip on;

    gzip_http_version 1.0;

    gzip_comp_level 6;

    gzip_proxied any;

    gzip_min_length  1100;

    gzip_buffers 16 8k;

    gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/jpeg;

    gzip_disable "MSIE [1-6].(?!.*SV1)";

    gzip_vary on;

    include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/sites-enabled/*;


Not quite sure what the problem is here. But a few other things: You should keep the request method out of the cache key. Compression for binary image formats is pointless if not harmful. And you can drastically shorten your gzip_types directive.

As for your problem: Enable debug logging and see what happens.

It’s my fault, i didn’t see default.conf , in which other instruction was there.

Question closed