在 nginx 上缓存 Zend Framework 主页

Cache Zend Framework homepage on nginx

我有基于 zend framework 1.12 的站点与 nginx 一起工作

我在windows7专业版上安装了wnmp来测试Windows、nginx、mariadb、php7

我想缓存 localhost 或 localhost/ 的主页 使用 index.php

在内部调用 index.php

类似 urls http://localhost/conference/sessions/date/2015-04/12/page/1 会议 - 控制器会话 - 操作请求参数日期,以及具有相应值的页面

我想缓存主页,但我已经看过,但没有任何具体可用的内容

这是我的 nginx.conf,无需缓存即可工作

这是我 nginx.conf

中的内容
worker_processes  1;
error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    # Max value 16384
    worker_connections  8192;
    # Accept multiple connections
    multi_accept on;
}

# Settings that affect all server blocks
http {
    include php_processes.conf;
    include       mime.types;
    default_type  application/octet-stream;
    access_log  logs/access.log;
fastcgi_buffers 16 16k; 
fastcgi_buffer_size 32k;

    sendfile on;

    keepalive_timeout  65;
    ssl_session_timeout 10m;
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS; 
    ssl_prefer_server_ciphers on;
    gzip  on;
    # http server

# Begin HTTP Server
server {
    listen 80; # IPv4
    server_name localhost;

    ## Parametrization using hostname of access and log filenames.
    access_log logs/localhost_access.log;
    error_log logs/localhost_error.log;

    ## Root and index files.
    root html;
    index  index.php index.html index.htm;
    ## If no favicon exists return a 204 (no content error).
    location = /favicon.ico {
        try_files $uri =204;
        log_not_found off;
        access_log off;
    }

    ## Don't log robots.txt requests.
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    ## Try the requested URI as files before handling it to PHP.
    location / {
        ## Regular PHP processing.
        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_pass   php_processes;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
        ## Static files
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
            expires max;
            log_not_found off;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=1000 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }
        ## Keep a tab on the 'big' static files.
        location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
            expires 30d;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
        }
        try_files $uri $uri/ @missing;
    } # / location
    location @missing {
        rewrite (.*) /index.php;
    }
}

请帮忙

在 http 下添加 注意 - 如果您的 cookie 以下划线 (_)

开头,请添加两个下划线 (__)
fastcgi_cache_path /home/k47/cache/nginx levels=1:2 keys_zone=MYHOMEPAGE:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_method$query_string$request_uri$cookie_one$cookie_two$cookie__ga$cookie__gat";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
fastcgi_cache_valid 200 302 1m;

在server下设置一个flag/variable可以用来判断我们是否需要缓存 我已经使用其他 url 来缓存而不是缓存类似的正则表达式

set $no_cache 1;
if ($request_uri ~* "^/$")
{
    set $no_cache 0;
}

然后终于在我开始的位置{}下

fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;         
fastcgi_cache MYHOMEPAGE;
fastcgi_cache_valid 200 1m;
add_header X-Proxy-Cache $upstream_cache_status;
add_header cache-control 'public, max-age=500';