Yii Framework Forum: Nginx Cache For Yii Project - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Nginx Cache For Yii Project how to made it Rate Topic: -----

#1 User is offline   turyczech 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 29-December 13

Posted 04 January 2014 - 09:39 AM

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;
                    }
            }

0

#2 User is offline   McQueen 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 136
  • Joined: 13-August 11
  • Location:Istanbul/Turkey

Posted 04 January 2014 - 09:48 AM

I dont think that its about yii...
i saw your post on stackoverflow but i dont have any idea..
0

#3 User is offline   turyczech 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 29-December 13

Posted 04 January 2014 - 09:58 AM

View PostMcQueen, on 04 January 2014 - 09:48 AM, said:

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 :)
0

#4 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,045
  • Joined: 16-February 11
  • Location:Japan

Posted 04 January 2014 - 10:09 AM

/* Moved from "General Discussion for Yii 1.1.x" to "Miscellaneous" */
0

#5 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 04 January 2014 - 10:11 AM

Is there a fastcgi_cache_path directive configured in your http block?
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#6 User is offline   turyczech 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 29-December 13

Posted 04 January 2014 - 10:32 AM

View PostDa:Sourcerer, on 04 January 2014 - 10:11 AM, said:


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

#7 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 04 January 2014 - 10:52 AM

common? What is common? Anyway, could you hsow us the aforementioned directive?
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#8 User is offline   turyczech 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 29-December 13

Posted 04 January 2014 - 11:07 AM

nginx.conf
user              nginx;
worker_processes  2;
error_log  /srv/logs/nginx-error.log;
pid        /var/run/nginx.pid;
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]'
                      '$gzip_ratio"';

    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/*;
}

0

#9 User is offline   Da:Sourcerer 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,222
  • Joined: 30-March 11
  • Location:Berlin, Germany

Posted 04 January 2014 - 11:23 AM

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.
programmer /ˈprəʊgramə/, noun: a device that converts ►coffee into ►code
0

#10 User is offline   turyczech 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 29-December 13

Posted 04 January 2014 - 11:31 AM

View PostDa:Sourcerer, on 04 January 2014 - 11:23 AM, said:

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
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users