2015-11-03 10 views
6

मैं केकेएफपी 1.3 का उपयोग कर रहा हूं, और कुछ संपत्ति थीम्ड संपत्तियां हैं (जेएस, आईएमजी इत्यादि) और अन्य थीम्ड संपत्ति नहीं हैं।मैं nginx कैश पुनर्लेखित संपत्ति कैसे बना सकता हूं?

गैर थीम्ड संपत्तियों को सही तरीके से कैश किया जाता है; लेकिन थीम्ड संपत्तियों को सही समाप्ति शीर्षलेख नहीं मिल रहे हैं। मैं थीम्ड संपत्तियों को खोजने में मदद के लिए स्थान ब्लॉक में पुनर्लेखन का उपयोग करता हूं, लेकिन किसी कारण से, nginx तब सही कैश हेडर लागू नहीं करता है।

मैं नीचे मेरी nginx config की एक प्रति संलग्न है। क्या किसी ने हल किया है कि पुनर्लेखित संपत्ति कैश कैसे करें?

user nginx; 
worker_processes 2; 

error_log /var/log/nginx/error.log; 

pid  /var/run/nginx.pid; 


events { 
    worker_connections 1024; 
} 

#----------------------------------------------------------------------------------------------------- 

http { 
    include  /etc/nginx/mime.types; 
    default_type application/octet-stream; 

    log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 
         '$status $body_bytes_sent "$http_referer" ' 
         '"$http_user_agent" "$http_x_forwarded_for"'; 

    access_log /var/log/nginx/access.log main; 

    sendfile  on; 
    #tcp_nopush  on; 

    #keepalive_timeout 0; 
    keepalive_timeout 65; 

    fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:100m inactive=60m; 
    fastcgi_cache_key "$scheme$request_method$host$request_uri"; 

    # Load modular configuration files from the /etc/nginx/conf.d directory. 
    # See http://nginx.org/en/docs/ngx_core_module.html#include 
    # for more information. 
    include /etc/nginx/conf.d/*.conf; 

server { 
    listen  80; 
    server_name ag_production; 
    access_log /var/log/nginx/ag.access.log; 
    error_log /var/log/nginx/ag.error.log; 
    rewrite_log on; 
    root  /var/www/html/app/webroot/; 
    index  index.php index.html index.htm; 

    set $no_cache 0; 

    location/{ 
     try_files $uri $uri/ @rules; 
    } 

    location @rules { 
     rewrite ^(.+)$ /index.php?url=$1 last; 
    } 

    # Pass the PHP scripts to FastCGI server 
    # listening on 127.0.0.1:9000 
    location ~ \.php$ { 
     #try_files $uri =404; 
     fastcgi_cache my_cache; 
     fastcgi_cache_valid 200 60m; # Only cache 200 responses, cache for 60 minutes 
     fastcgi_cache_methods GET HEAD; # Only GET and HEAD methods apply 
     add_header X-Fastcgi-Cache $upstream_cache_status; 
     fastcgi_cache_bypass $no_cache; # Don't pull from cache based on $no_cache 
     fastcgi_no_cache $no_cache; # Don't save to cache based on $no_cache 
     fastcgi_buffer_size 128k; 
     fastcgi_buffers 256 4k; 
     fastcgi_busy_buffers_size 256k; 
     fastcgi_temp_file_write_size 256k; 

     # fastcgi_pass unix:/tmp/php-fastcgi.sock; 
     fastcgi_pass 127.0.0.1:9000; 
     fastcgi_index index.php; 
     fastcgi_intercept_errors on; # to support 404s for PHP files not found 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
     include  fastcgi_params; 
    } 

    location ~* \.(?:manifest|appcache|html?|xml|json)$ { 
     try_files $uri $uri/ @rules; 
     expires -1; 
     access_log logs/static.log; # I don't usually include a static log 
    } 

    # Feed 
    location ~* \.(?:rss|atom)$ { 
     try_files $uri $uri/ @rules; 
     expires 1h; 
     add_header Pragma "public"; 
       add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 
    } 

    # Media: images, icons, video, audio, HTC 
    location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { 
     expires 1M; 
     access_log off; 
     add_header Pragma "public"; 
     add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 
     try_files $uri $uri/ @rules; 

    } 

    # CSS and Javascript 
    location ~* \.(?:css|js)$ { 
     try_files $uri $uri/ @rules; 
     expires 1y; 
     access_log off; 
       add_header Pragma "public"; 
       add_header Cache-Control "public, must-revalidate, proxy-revalidate"; 
    } 

    # Deny access to .htaccess files, 
    # git & svn repositories, etc 
    location ~ /(\.ht|\.git|\.svn) { 
     deny all; 
    } 
} 
} 

उत्तर

4

हाँ, विषय संपत्ति CakePHP में कम होती है, यह भी किया गया है उनके आधिकारिक दस्तावेज में here का वर्णन किया।

समाधान, nginx के माध्यम से इन विषय संपत्ति की सेवा के लिए try_files का उपयोग कर रहा है।

# Serve CakePHP plugin assets directly 
location ~ /(.+)/(img|css|js|files)/(.*) { 
    access_log off; 
    expires 10d; 
    add_header Cache-Control public; 
    try_files $uri $uri/ /../plugins/$1/webroot/$2/$3 /../../plugins/$1/webroot/$2/$3 /index.php?url=$uri; 
} 

(source)

+0

यह मेरे सवाल का जवाब नहीं है:

यहाँ ऊपर प्रयोजन के लिए एक उदाहरण nginx विन्यास है। यह पहले से ही स्पष्ट है कि मैं कोशिश करने वाली फाइलों का उपयोग कर रहा हूं, जो मुझे उलझन में है, वह यह है कि Nginx समाप्त होने वाले शीर्षकों को सही ढंग से सेट नहीं करेगा, यह हमेशा 24 घंटों तक चूक जाता है। कृपया मेरा प्रश्न फिर से पढ़ें। – user1658296

संबंधित मुद्दे