Skip to content

Commit b136829

Browse files
authored
Merge pull request hestiacp#2037 from hestiacp/fix-caching
Fix caching template when nginx is used as reverse proxy
2 parents e83d013 + f34fcc1 commit b136829

File tree

4 files changed

+34
-11
lines changed

4 files changed

+34
-11
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ All notable changes to this project will be documented in this file.
1010

1111
### Bugfixes
1212

13-
- Fix UI issues after upgrade jQuery + jQuery UI to last version (#2021 and #2032)
13+
- Fixed UI issues after upgrade jQuery + jQuery UI to last version (#2021 and #2032)
14+
- Fixed security issues in caching templates of Nginx when used as Reverse Proxy
1415

1516
## [1.4.9] - Service release
1617

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ ip=$3
66
home=$4
77
docroot=$5
88

9-
str="proxy_cache_path /var/cache/nginx/$domain levels=2"
10-
str="$str keys_zone=$domain:10m inactive=60m max_size=512m;"
9+
str="proxy_cache_path /var/cache/nginx/$domain levels=1:2"
10+
str="$str keys_zone=$domain:10m max_size=256m inactive=30m;"
1111
conf='/etc/nginx/conf.d/01_caching_pool.conf'
1212
if [ -e "$conf" ]; then
1313
if [ -z "$(grep "=${domain}:" $conf)" ]; then

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,22 @@ server {
1818
proxy_pass https://%ip%:%web_ssl_port%;
1919

2020
proxy_cache %domain%;
21-
proxy_cache_valid 15m;
22-
proxy_cache_valid 404 1m;
21+
proxy_cache_valid 200 5m;
22+
proxy_cache_valid 301 302 10m;
23+
proxy_cache_valid 404 10m;
24+
proxy_cache_bypass $no_cache $cookie_session $http_x_update;
2325
proxy_no_cache $no_cache;
24-
proxy_cache_bypass $no_cache;
25-
proxy_cache_bypass $cookie_session $http_x_update;
26+
27+
set $no_cache 0;
28+
if ($request_uri ~* "/wp-admin/|wp-.*.php|xmlrpc.php|/store.*|/cart.*|/my-account.*|/checkout.*|/user/|/admin/|/administrator/|/manager/|index.php") {
29+
set $no_cache 1;
30+
}
31+
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
32+
set $no_cache 1;
33+
}
34+
if ($http_cookie ~ SESS) {
35+
set $no_cache 1;
36+
}
2637

2738
location ~* ^.+\.(%proxy_extensions%)$ {
2839
proxy_cache off;

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,22 @@ server {
1313
proxy_pass http://%ip%:%web_port%;
1414
1515
proxy_cache %domain%;
16-
proxy_cache_valid 15m;
17-
proxy_cache_valid 404 1m;
16+
proxy_cache_valid 200 5m;
17+
proxy_cache_valid 301 302 10m;
18+
proxy_cache_valid 404 10m;
19+
proxy_cache_bypass $no_cache $cookie_session $http_x_update;
1820
proxy_no_cache $no_cache;
19-
proxy_cache_bypass $no_cache;
20-
proxy_cache_bypass $cookie_session $http_x_update;
21+
22+
set $no_cache 0;
23+
if ($request_uri ~* "/wp-admin/|wp-.*.php|xmlrpc.php|/store.*|/cart.*|/my-account.*|/checkout.*|/user/|/admin/|/administrator/|/manager/|index.php") {
24+
set $no_cache 1;
25+
}
26+
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|woocommerce_items_in_cart|woocommerce_cart_hash|PHPSESSID") {
27+
set $no_cache 1;
28+
}
29+
if ($http_cookie ~ SESS) {
30+
set $no_cache 1;
31+
}
2132

2233
location ~* ^.+\.(%proxy_extensions%)$ {
2334
proxy_cache off;

0 commit comments

Comments
 (0)