Skip to content

Instantly share code, notes, and snippets.

@stefpe
Created June 7, 2019 21:01
Show Gist options
  • Save stefpe/1e952e4c7f8ec3726ee4f4f64a927e38 to your computer and use it in GitHub Desktop.
Save stefpe/1e952e4c7f8ec3726ee4f4f64a927e38 to your computer and use it in GitHub Desktop.
nginx fastcgi caching reverse proxy
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=fpmcache:100m max_size=10g inactive=60m use_temp_path=off;
fastcgi_cache_key "$request_uri|$request_body";
fastcgi_cache_methods POST;
server {
server_tokens off;
listen 80 default_server;
server_name server_name _;
access_log /dev/stdout;
error_log /dev/stderr;
root /opt/code;
location / {
try_files $uri /index.php$is_args$args;
}
set $disable_cache 1;
if ($request_uri ~ "^/cache") {set $disable_cache 0;}
location ~ [^/]\.php(/|$) {
fastcgi_cache_bypass $disable_cache;
fastcgi_no_cache $disable_cache;
fastcgi_cache fpmcache;
fastcgi_cache_valid 200 15m;
fastcgi_cache_min_uses 1;
fastcgi_cache_lock on;
add_header X-FastCGI-Cache $upstream_cache_status;
#basic fpm settings
fastcgi_pass fpm:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
fastcgi_read_timeout 35;
include fastcgi_params;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment