Skip to content

Commit 24e273f

Browse files
committed
Adds caching template for nginx + php-fpm, and resolves a typo in the regular nginx caching template
1 parent 90f5e24 commit 24e273f

File tree

6 files changed

+150
-2
lines changed

6 files changed

+150
-2
lines changed

install/deb/nginx/nginx.conf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ http {
131131
proxy_cache_use_stale error timeout invalid_header http_502;
132132
proxy_cache_valid any 1d;
133133

134+
# FastCGI Cache settings
135+
fastcgi_cache_path /var/cache/nginx/php-fpm levels=2 keys_zone=cache:10m inactive=60m max_size=1024m;
136+
fastcgi_cache_key "$host$request_uri $cookie_user";
137+
fastcgi_temp_path /var/cache/nginx/temp;
138+
fastcgi_ignore_headers Expires Cache-Control;
139+
fastcgi_cache_use_stale error timeout invalid_header;
140+
fastcgi_cache_valid any 1d;
141+
134142
# Cache bypass
135143
map $http_cookie $no_cache {
136144
default 0;

install/deb/templates/web/nginx/caching.stpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ server {
1717
location / {
1818
proxy_pass https://%ip%:%web_ssl_port%;
1919

20-
proxy_cache cache;
20+
proxy_cache %domain%;
2121
proxy_cache_valid 15m;
2222
proxy_cache_valid 404 1m;
2323
proxy_no_cache $no_cache;

install/deb/templates/web/nginx/caching.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ server {
1212
location / {
1313
proxy_pass http://%ip%:%web_port%;
1414
15-
proxy_cache cache;
15+
proxy_cache %domain%;
1616
proxy_cache_valid 15m;
1717
proxy_cache_valid 404 1m;
1818
proxy_no_cache $no_cache;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
user=$1
4+
domain=$2
5+
ip=$3
6+
home=$4
7+
docroot=$5
8+
9+
str="fastcgi_cache_path /var/cache/nginx/php-fpm/$domain levels=2"
10+
str="$str keys_zone=$domain:10m inactive=60m max_size=512m;"
11+
conf='/etc/nginx/conf.d/01_caching_pool.conf'
12+
if [ -e "$conf" ]; then
13+
if [ -z "$(grep "=${domain}:" $conf)" ]; then
14+
echo "$str" >> $conf
15+
fi
16+
else
17+
echo "$str" >> $conf
18+
fi
19+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#=======================================================================#
2+
# Default Web Domain Template #
3+
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
4+
#=======================================================================#
5+
6+
server {
7+
listen %ip%:%web_ssl_port% ssl http2;
8+
server_name %domain_idn% %alias_idn%;
9+
root %sdocroot%;
10+
index index.php index.html index.htm;
11+
access_log /var/log/nginx/domains/%domain%.log combined;
12+
access_log /var/log/nginx/domains/%domain%.bytes bytes;
13+
error_log /var/log/nginx/domains/%domain%.error.log error;
14+
15+
ssl_certificate %ssl_pem%;
16+
ssl_certificate_key %ssl_key%;
17+
ssl_stapling on;
18+
ssl_stapling_verify on;
19+
20+
include %home%/%user%/conf/web/%domain%/nginx.hsts.conf*;
21+
22+
location / {
23+
24+
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
25+
expires max;
26+
fastcgi_hide_header "Set-Cookie";
27+
}
28+
29+
location ~ [^/]\.php(/|$) {
30+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
31+
if (!-f $document_root$fastcgi_script_name) {
32+
return 404;
33+
}
34+
35+
fastcgi_pass %backend_lsnr%;
36+
fastcgi_index index.php;
37+
include /etc/nginx/fastcgi_params;
38+
39+
fastcgi_cache %domain%;
40+
fastcgi_no_cache $no_cache;
41+
fastcgi_cache_bypass $no_cache;
42+
fastcgi_cache_bypass $cookie_session $http_x_update;
43+
}
44+
}
45+
46+
location /error/ {
47+
alias %home%/%user%/web/%domain%/document_errors/;
48+
}
49+
50+
location ~* "/\.(htaccess|htpasswd)$" {
51+
deny all;
52+
return 404;
53+
}
54+
55+
location /vstats/ {
56+
alias %home%/%user%/web/%domain%/stats/;
57+
include %home%/%user%/web/%domain%/stats/auth.conf*;
58+
}
59+
60+
include /etc/nginx/conf.d/phpmyadmin.inc*;
61+
include /etc/nginx/conf.d/phppgadmin.inc*;
62+
include %home%/%user%/conf/web/%domain%/nginx.ssl.conf_*;
63+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#=======================================================================#
2+
# Default Web Domain Template #
3+
# DO NOT MODIFY THIS FILE! CHANGES WILL BE LOST WHEN REBUILDING DOMAINS #
4+
#=======================================================================#
5+
6+
server {
7+
listen %ip%:%web_port%;
8+
server_name %domain_idn% %alias_idn%;
9+
root %docroot%;
10+
index index.php index.html index.htm;
11+
access_log /var/log/nginx/domains/%domain%.log combined;
12+
access_log /var/log/nginx/domains/%domain%.bytes bytes;
13+
error_log /var/log/nginx/domains/%domain%.error.log error;
14+
15+
include %home%/%user%/conf/web/%domain%/nginx.forcessl.conf*;
16+
17+
location / {
18+
19+
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
20+
expires max;
21+
fastcgi_hide_header "Set-Cookie";
22+
}
23+
24+
location ~ [^/]\.php(/|$) {
25+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
26+
if (!-f $document_root$fastcgi_script_name) {
27+
return 404;
28+
}
29+
30+
fastcgi_pass %backend_lsnr%;
31+
fastcgi_index index.php;
32+
include /etc/nginx/fastcgi_params;
33+
34+
fastcgi_cache %domain%;
35+
fastcgi_no_cache $no_cache;
36+
fastcgi_cache_bypass $no_cache;
37+
fastcgi_cache_bypass $cookie_session $http_x_update;
38+
}
39+
}
40+
41+
location /error/ {
42+
alias %home%/%user%/web/%domain%/document_errors/;
43+
}
44+
45+
location ~* "/\.(htaccess|htpasswd)$" {
46+
deny all;
47+
return 404;
48+
}
49+
50+
location /vstats/ {
51+
alias %home%/%user%/web/%domain%/stats/;
52+
include %home%/%user%/web/%domain%/stats/auth.conf*;
53+
}
54+
55+
include /etc/nginx/conf.d/phpmyadmin.inc*;
56+
include /etc/nginx/conf.d/phppgadmin.inc*;
57+
include %home%/%user%/conf/web/%domain%/nginx.conf_*;
58+
}

0 commit comments

Comments
 (0)