Skip to content

Instantly share code, notes, and snippets.

@igortik
Last active April 6, 2016 18:38
Show Gist options
  • Select an option

  • Save igortik/cc542f237c02bcdc772fd362edb05cc6 to your computer and use it in GitHub Desktop.

Select an option

Save igortik/cc542f237c02bcdc772fd362edb05cc6 to your computer and use it in GitHub Desktop.

Revisions

  1. igortik revised this gist Apr 6, 2016. 1 changed file with 62 additions and 57 deletions.
    119 changes: 62 additions & 57 deletions nginx_php_fpm_cache.conf
    Original file line number Diff line number Diff line change
    @@ -1,60 +1,65 @@
    location ~ \.php$ {
    internal;
    server {

    root $engine_root;

    # All requests to default > /index.php
    try_files index.php =404;

    # Lifetime
    fastcgi_cache_valid 200 301 302 304 5m;

    # After how much requests answer will be cached
    fastcgi_cache_min_uses 1;

    # Sequrity
    #
    # Cache will not be created if backend is setting cookies
    # (!) this directive will allow creating cache with user cookies content
    # Be careful, because cookies contains users private data and sessions
    #
    #fastcgi_ignore_headers Set-Cookie;

    # Cookies visibility
    #
    # this directive deprecates sending cookies to client (browser etc.)
    # in case when creating cache Set-Cookie header will not be present in cache file
    #
    #fastcgi_hide_header Set-Cookie;

    # Exceptions
    #
    # do not cache result when client sends $_COOKIE['nocahe'] or has arg ?nocache=1
    #
    fastcgi_no_cache $cookie_nocache $arg_nocache;
    #
    # do not take result from cache when client sends $_COOKIE['nocache'] or has arg ?nocache=1
    #
    fastcgi_cache_bypass $cookie_nocache $arg_nocache;
    #
    # regenerate cache with header:
    # curl -s -o /dev/null -H "X-Update-Cache: 1" www.example.com
    #
    fastcgi_cache_bypass $http_x_update_cache;

    # Config
    #
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_cache fastcgi_cache;
    fastcgi_cache_methods GET HEAD;
    fastcgi_ignore_headers Cache-Control Expires;
    fastcgi_cache_key "$scheme|$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
    fastcgi_cache_use_stale updating error timeout invalid_header http_500;
    # ...

    # Params
    #
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    include fastcgi_params;
    location ~ \.php$ {
    internal;

    root /path;

    # All requests to default > /index.php
    try_files index.php =404;

    # Lifetime
    fastcgi_cache_valid 200 301 302 304 5m;

    # After how much requests answer will be cached
    fastcgi_cache_min_uses 1;

    # Sequrity
    #
    # Cache will not be created if backend is setting cookies
    # (!) this directive will allow creating cache with user cookies content
    # Be careful, because cookies contains users private data and sessions
    #
    #fastcgi_ignore_headers Set-Cookie;

    # Cookies visibility
    #
    # this directive deprecates sending cookies to client (browser etc.)
    # in case when creating cache Set-Cookie header will not be present in cache file
    #
    #fastcgi_hide_header Set-Cookie;

    # Exceptions
    #
    # do not cache result when client sends $_COOKIE['nocahe'] or has arg ?nocache=1
    #
    fastcgi_no_cache $cookie_nocache $arg_nocache;
    #
    # do not take result from cache when client sends $_COOKIE['nocache'] or has arg ?nocache=1
    #
    fastcgi_cache_bypass $cookie_nocache $arg_nocache;
    #
    # regenerate cache with header:
    # curl -s -o /dev/null -H "X-Update-Cache: 1" www.example.com
    #
    fastcgi_cache_bypass $http_x_update_cache;

    # Config
    #
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_cache fastcgi_cache;
    fastcgi_cache_methods GET HEAD;
    fastcgi_ignore_headers Cache-Control Expires;
    fastcgi_cache_key "$scheme|$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
    fastcgi_cache_use_stale updating error timeout invalid_header http_500;

    # Params
    #
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    include fastcgi_params;
    }
    }
  2. igortik created this gist Apr 6, 2016.
    60 changes: 60 additions & 0 deletions nginx_php_fpm_cache.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,60 @@
    location ~ \.php$ {
    internal;

    root $engine_root;

    # All requests to default > /index.php
    try_files index.php =404;

    # Lifetime
    fastcgi_cache_valid 200 301 302 304 5m;

    # After how much requests answer will be cached
    fastcgi_cache_min_uses 1;

    # Sequrity
    #
    # Cache will not be created if backend is setting cookies
    # (!) this directive will allow creating cache with user cookies content
    # Be careful, because cookies contains users private data and sessions
    #
    #fastcgi_ignore_headers Set-Cookie;

    # Cookies visibility
    #
    # this directive deprecates sending cookies to client (browser etc.)
    # in case when creating cache Set-Cookie header will not be present in cache file
    #
    #fastcgi_hide_header Set-Cookie;

    # Exceptions
    #
    # do not cache result when client sends $_COOKIE['nocahe'] or has arg ?nocache=1
    #
    fastcgi_no_cache $cookie_nocache $arg_nocache;
    #
    # do not take result from cache when client sends $_COOKIE['nocache'] or has arg ?nocache=1
    #
    fastcgi_cache_bypass $cookie_nocache $arg_nocache;
    #
    # regenerate cache with header:
    # curl -s -o /dev/null -H "X-Update-Cache: 1" www.example.com
    #
    fastcgi_cache_bypass $http_x_update_cache;

    # Config
    #
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_cache fastcgi_cache;
    fastcgi_cache_methods GET HEAD;
    fastcgi_ignore_headers Cache-Control Expires;
    fastcgi_cache_key "$scheme|$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
    fastcgi_cache_use_stale updating error timeout invalid_header http_500;

    # Params
    #
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    include fastcgi_params;
    }