Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cern-drupal-distribution
Manage
Activity
Members
Labels
Plan
Issues
11
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
10
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
drupal
paas
cern-drupal-distribution
Merge requests
!128
Bp 'nginx-cache'
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Bp 'nginx-cache'
bp-v9.3-2
into
v9.3-2
Overview
0
Commits
1
Pipelines
1
Changes
1
Merged
Konstantinos Samaras-Tsakiris
requested to merge
bp-v9.3-2
into
v9.3-2
2 years ago
Overview
0
Commits
1
Pipelines
1
Changes
1
Expand
Add nginx cache
Closes webservices/webframeworks-planning#772
Backport merge request
!126 (merged)
👍
0
👎
0
Merge request reports
Compare
v9.3-2
version 1
8d7487f6
2 years ago
v9.3-2 (base)
and
latest version
latest version
8d7487f6
1 commit,
2 years ago
version 1
8d7487f6
1 commit,
2 years ago
1 file
+
85
−
7
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
images/nginx/config/nginx-server-default.conf
+
85
−
7
Options
@@ -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
:
20
m
levels
=
1
:
2
inactive
=
900
s
max_size
=
200
m
;
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
120
s
;
fastcgi_cache_valid
404
30
s
;
fastcgi_cache_lock
on
;
fastcgi_cache_lock_age
30
s
;
fastcgi_cache_lock_timeout
90
s
;
# 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