Skip to content

Commit 144e014

Browse files
committed
Fix doc; Add support for WP Fastest Cache!
1 parent 7082150 commit 144e014

File tree

4 files changed

+138
-5
lines changed

4 files changed

+138
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ sudo cp -a /etc/nginx $HOME/nginx-backup-$TIMESTAMP
7070
Step #3 - Copy this repo to your server.
7171

7272
```bash
73-
git clone git://github.com/pothi/wordpress-nginx.git $HOME/git/wordpress-nginx
73+
git clone https://github.com/pothi/wordpress-nginx.git $HOME/git/wordpress-nginx
7474
sudo cp -a $HOME/git/wordpress-nginx/* /etc/nginx/
7575
sudo mkdir /etc/nginx/sites-enabled &> /dev/null
7676
sudo cp /etc/nginx/nginx-sample.conf /etc/nginx/nginx.conf

globals/wp-fastest-cache.conf

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# configuration directives to support WP Fastest Cache plugin.
2+
# note not all features are supported.
3+
4+
# default location block
5+
# - directs mobile visitors to @mobileaccess, if configured.
6+
# - directs cache misses to PHP (via @cachemiss).
7+
# - directs requests "that shouldn't be cached" to PHP (via @cachemiss): example - requests from a logged-in user.
8+
location / {
9+
error_page 418 = @cachemiss; # to handle cache misses
10+
error_page 419 = @mobileaccess; # to handle mobile visits
11+
recursive_error_pages on;
12+
13+
# bypass POST requests
14+
if ($request_method = POST) { return 418; }
15+
16+
# uncommenting the following degrades the performance on certain sites. YMMV
17+
# if ($query_string != "") { return 418; }
18+
19+
# bypass cache for common query strings
20+
if ($arg_s != "") { return 418; } # search query
21+
if ($arg_p != "") { return 418; } # request a post / page by ID
22+
if ($arg_amp != "") { return 418; } # amp test
23+
if ($arg_preview = "true") { return 418; } # preview post / page
24+
if ($arg_ao_noptimize != "") { return 418; } # support for Autoptimize plugin
25+
26+
# if WP related cookies are found, skip cache
27+
if ($http_cookie ~* "wordpress_logged_in_") { return 418; }
28+
if ($http_cookie ~* "comment_author_") { return 418; }
29+
if ($http_cookie ~* "wp_postpass_") { return 418; }
30+
31+
# uncomment the following two lines to support mobile cache
32+
# if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|iPad)) { return 419; }
33+
# add_header "Vary" "User-Agent";
34+
35+
# uncomment the following if deemed fit
36+
# if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-|ipad)) { return 419; }
37+
38+
# look for cached version; if-not-found, then send the request to PHP
39+
try_files "/wp-content/cache/all/${uri}index.html" $uri $uri/ /index.php$is_args$args;
40+
41+
#--> all the following would apply, only if the request hits the cache
42+
43+
# add some useful headers
44+
add_header "X-Cache" "HIT";
45+
add_header "X-CF-Powered-By" "WP Fastest Cache";
46+
add_header "Vary" "Cookie";
47+
# include "globals/hsts.conf";
48+
49+
expires 30m;
50+
# expires modified 30m;
51+
add_header "Cache-Control" "must-revalidate";
52+
53+
# For proxies
54+
# add_header "Cache-Control" "s-maxage=600";
55+
}
56+
57+
# location to handle requests come from mobile devices
58+
location @mobileaccess {
59+
# look for cached version for mobiles; if-not-found, then send the request to PHP
60+
try_files "/wp-content/cache/all/${uri}index.html" $uri $uri/ /index.php$is_args$args;
61+
62+
#--> all the following would apply, only if the request hits the cache
63+
64+
# add some useful headers
65+
add_header "X-Cache" "HIT - Mobile";
66+
add_header "X-CF-Powered-By" "WP Fastest Cache";
67+
add_header "Vary" "User-Agent, Cookie";
68+
# include "globals/hsts.conf";
69+
70+
expires 30m;
71+
# expires modified 30m;
72+
add_header "Cache-Control" "must-revalidate";
73+
74+
# For proxies
75+
# add_header "Cache-Control" "s-maxage=600";
76+
}
77+
78+
location @cachemiss {
79+
# on cache miss, send the request to PHP
80+
try_files $uri $uri/ /index.php$is_args$args;
81+
}

globals/wprocket.conf

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ location / {
3131
if ($http_cookie ~* "wp_postpass_") { return 418; }
3232

3333
# if ($http_user_agent ~* (2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800|iPad)) { return 419; }
34+
# add_header "Vary" "User-Agent";
3435

3536
# uncomment the following if deemed fit
3637
# if ($http_user_agent ~* (w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-|ipad)) { return 419; }
3738

38-
try_files "/wp-content/cache/wp-rocket/$host${uri}index$wpsc_https.html" $uri $uri/ /index.php$is_args$args;
39+
try_files "/wp-content/cache/wp-rocket/$host${uri}$is_args$args/index$wpsc_https.html" $uri $uri/ /index.php$is_args$args;
3940

4041
#--> all the following would apply, only if the request hits the cache
4142

42-
add_header "X-Cache" "HIT - WP Rocket Cache";
43+
add_header "X-Cache" "HIT - Desktop";
44+
add_header "X-CF-Powered-By" "WP Rocket";
45+
add_header "Vary" "Cookie";
4346
# include "globals/hsts.conf";
4447

4548
expires modified 30m;
@@ -51,9 +54,11 @@ location / {
5154

5255
location @mobileaccess {
5356
# try_files $uri $uri/ /index.php$is_args$args;
54-
try_files "/wp-content/cache/wp-rocket/$host${uri}index-mobile$wpsc_https.html" $uri $uri/ /index.php$is_args$args;
57+
try_files "/wp-content/cache/wp-rocket/$host${uri}$is_args$args/index-mobile$wpsc_https.html" $uri $uri/ /index.php$is_args$args;
5558

56-
add_header "X-Cache" "HIT - Mobile - WP Rocket Cache";
59+
add_header "X-Cache" "HIT - Mobile";
60+
add_header "X-CF-Powered-By" "WP Rocket";
61+
add_header "Vary" "User-Agent, Cookie";
5762
# include "globals/hsts.conf";
5863

5964
expires modified 30m;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
server {
2+
listen 80;
3+
listen 443 ssl http2;
4+
server_name dev.example.com;
5+
index index.php;
6+
7+
# Replace the path with the actual path to WordPress core files
8+
root /home/dev/sites/dev.example.com/public;
9+
10+
# ssl_certificate "/etc/letsencrypt/live/dev.example.com/fullchain.pem";
11+
# ssl_certificate_key "/etc/letsencrypt/live/dev.example.com/privkey.pem";
12+
13+
# access_log off;
14+
access_log /var/log/nginx/dev-example.com-access.log;
15+
error_log /var/log/nginx/dev-example.com-error.log;
16+
# error_log /var/log/nginx/dev-example.com-error.log debug;
17+
18+
include "globals/restrictions.conf";
19+
20+
location ~* \.(?:css|js|jpg|jpeg|png|gif|ico|svg|ttf|eot|woff|otf)$ { expires max; try_files $uri @prod; }
21+
22+
location @prod {
23+
proxy_pass https://0.0.0.0;
24+
25+
proxy_set_header Host "www.example.com";
26+
27+
proxy_set_header X-Real-IP $remote_addr;
28+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29+
proxy_set_header X-Forwarded-Proto $scheme;
30+
}
31+
32+
location ~ \.php$ {
33+
try_files $uri =404;
34+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
35+
36+
include fastcgi.conf;
37+
fastcgi_index index.php;
38+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
39+
fastcgi_intercept_errors on;
40+
fastcgi_pass fpm-dev;
41+
}
42+
43+
# The rewrite magic
44+
location / { try_files $uri $uri/ /index.php$is_args$args; }
45+
# include "globals/wpsc.conf";
46+
# include "globals/wprocket.conf";
47+
}

0 commit comments

Comments
 (0)