Skip to content
Snippets Groups Projects

Bp 'nginx-cache'

Merged Konstantinos Samaras-Tsakiris requested to merge bp-v9.3-2 into v9.3-2
1 file
+ 85
7
Compare changes
  • Side-by-side
  • Inline
@@ -9,7 +9,43 @@ upstream webdav {
server unix:/var/run/webdav.sock;
}
#proxy_cache_path /var/cache/nginx keys_zone=one:10m max_size=200m;
## Global cache configuration ##
fastcgi_cache_path /var/cache/nginx keys_zone=cache:20m levels=1:2 inactive=900s max_size=200m;
fastcgi_cache_key "$request";
# Skip cache under the following conditions
# POST requests should always go to PHP
map $request_method $skip_cache_method {
"POST" 1;
}
# Don't cache URIs containing the following segments
# This includes WebDAV, _site, admin, cron, feeds etc
map $request_uri $skip_cache_uri {
"~^/_webdav" 1;
"~^/_site" 1;
"~^/admin/" 1;
"~/xmlrpc.php" 1;
"~^/cron" 1;
"~^/feeds" 1;
"~/tag/.*/feed/" 1;
"~/.*sitemap.*\.(xml|xsl)" 1;
}
# Don't use the cache for logged in users or recent commenters
# The `SSESS.*` cookies are PHP sessions, indicating logged in users
# Not caching when this kind of cookie is present means NOT caching responses to signed in users
# Reference: https://drupal.stackexchange.com/questions/267571/what-is-the-difference-between-a-drupal-session-variable-and-a-cookie
# Note that we're using `SSESS` and not only `SESS` to avoid confusion with other cookies, such as `INVENIOSESS`.
map $http_cookie $skip_cache_cookie {
"~comment_author" 1;
"~drupal_no_cache" 1;
"~SSESS" 1;
}
# Don't cache queries from localhost, which are either health checks or debugging
map $remote_addr $skip_cache_addr {
"127.0.0.1" 1;
}
server {
#listen 8080 ssl;
@@ -27,15 +63,51 @@ server {
gzip_vary on;
gzip_min_length 1000;
gzip_comp_level 5;
gzip_types application/json text/css text/javascript application/x-javascript application/javascript image/svg+xml;
gzip_types application/json text/css text/plain application/xml text/javascript application/x-javascript application/javascript image/svg+xml;
gzip_proxied any;
sendfile on;
keepalive_timeout 25;
# CACHE #
etag off;
fastcgi_cache cache;
fastcgi_cache_methods GET HEAD;
fastcgi_cache_min_uses 1;
fastcgi_cache_valid 200 302 120s;
fastcgi_cache_valid 404 30s;
fastcgi_cache_lock on;
fastcgi_cache_lock_age 30s;
fastcgi_cache_lock_timeout 90s;
# Serve stale content
fastcgi_cache_background_update on;
#fastcgi_cache_use_stale updating timeout invalid_header;
fastcgi_cache_use_stale error updating timeout invalid_header;
# DEBUG
# Header that shows if the content was served from the cache or not
# This information might be valuable for DoS attacks, so don't enable it in production
#add_header X-FastCGI-Cache $upstream_cache_status;
# source: https://www.linuxbabe.com/nginx/setup-nginx-fastcgi-cache
set $skip_cache 0;
if ($skip_cache_method) {
set $skip_cache 1;
}
if ($skip_cache_uri) {
set $skip_cache 1;
}
if ($skip_cache_cookie) {
set $skip_cache 1;
}
if ($skip_cache_addr) {
set $skip_cache 1;
}
sendfile on;
tcp_nopush on;
keepalive_timeout 90;
# Hide version headers
etag off;
server_tokens off;
# Disables specifying the port in absolute redirects
@@ -81,6 +153,8 @@ server {
location ^~ /_site/_php-fpm-status {
allow 127.0.0.1;
deny all;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
@@ -92,6 +166,9 @@ server {
}
# WebDAV Page
location ^~ /_webdav {
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
# Security note: If you're running a version of PHP older than the
# latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
@@ -173,6 +250,9 @@ server {
# pattern with front controllers other than update.php in a future
# release.
location ~ '\.php$|^/update.php' {
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
# Security note: If you're running a version of PHP older than the
# latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
@@ -185,8 +265,6 @@ server {
fastcgi_param QUERY_STRING $query_string;
fastcgi_intercept_errors on;
fastcgi_read_timeout 200;
# PHP 5 socket location.
#fastcgi_pass unix:/var/run/php5-fpm.sock;
# PHP 7 socket location.
fastcgi_pass php;
}
Loading