Last active
April 6, 2016 18:38
-
-
Save igortik/cc542f237c02bcdc772fd362edb05cc6 to your computer and use it in GitHub Desktop.
Nginx location example for PHP-FPM with cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
# ... | |
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment