Skip to content

Commit

Permalink
Fix doc; Add support for WP Fastest Cache!
Browse files Browse the repository at this point in the history
  • Loading branch information
pothi committed Dec 20, 2017
1 parent 7082150 commit 144e014
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ sudo cp -a /etc/nginx $HOME/nginx-backup-$TIMESTAMP
Step #3 - Copy this repo to your server.

```bash
git clone git://github.com/pothi/wordpress-nginx.git $HOME/git/wordpress-nginx
git clone https://github.com/pothi/wordpress-nginx.git $HOME/git/wordpress-nginx
sudo cp -a $HOME/git/wordpress-nginx/* /etc/nginx/
sudo mkdir /etc/nginx/sites-enabled &> /dev/null
sudo cp /etc/nginx/nginx-sample.conf /etc/nginx/nginx.conf
Expand Down
81 changes: 81 additions & 0 deletions globals/wp-fastest-cache.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# configuration directives to support WP Fastest Cache plugin.
# note not all features are supported.

# default location block
# - directs mobile visitors to @mobileaccess, if configured.
# - directs cache misses to PHP (via @cachemiss).
# - directs requests "that shouldn't be cached" to PHP (via @cachemiss): example - requests from a logged-in user.
location / {
error_page 418 = @cachemiss; # to handle cache misses
error_page 419 = @mobileaccess; # to handle mobile visits
recursive_error_pages on;

# bypass POST requests
if ($request_method = POST) { return 418; }

# uncommenting the following degrades the performance on certain sites. YMMV
# if ($query_string != "") { return 418; }

# bypass cache for common query strings
if ($arg_s != "") { return 418; } # search query
if ($arg_p != "") { return 418; } # request a post / page by ID
if ($arg_amp != "") { return 418; } # amp test
if ($arg_preview = "true") { return 418; } # preview post / page
if ($arg_ao_noptimize != "") { return 418; } # support for Autoptimize plugin

# if WP related cookies are found, skip cache
if ($http_cookie ~* "wordpress_logged_in_") { return 418; }
if ($http_cookie ~* "comment_author_") { return 418; }
if ($http_cookie ~* "wp_postpass_") { return 418; }

# uncomment the following two lines to support mobile cache
# 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; }
# add_header "Vary" "User-Agent";

# uncomment the following if deemed fit
# 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; }

# look for cached version; if-not-found, then send the request to PHP
try_files "/wp-content/cache/all/${uri}index.html" $uri $uri/ /index.php$is_args$args;

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

# add some useful headers
add_header "X-Cache" "HIT";
add_header "X-CF-Powered-By" "WP Fastest Cache";
add_header "Vary" "Cookie";
# include "globals/hsts.conf";

expires 30m;
# expires modified 30m;
add_header "Cache-Control" "must-revalidate";

# For proxies
# add_header "Cache-Control" "s-maxage=600";
}

# location to handle requests come from mobile devices
location @mobileaccess {
# look for cached version for mobiles; if-not-found, then send the request to PHP
try_files "/wp-content/cache/all/${uri}index.html" $uri $uri/ /index.php$is_args$args;

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

# add some useful headers
add_header "X-Cache" "HIT - Mobile";
add_header "X-CF-Powered-By" "WP Fastest Cache";
add_header "Vary" "User-Agent, Cookie";
# include "globals/hsts.conf";

expires 30m;
# expires modified 30m;
add_header "Cache-Control" "must-revalidate";

# For proxies
# add_header "Cache-Control" "s-maxage=600";
}

location @cachemiss {
# on cache miss, send the request to PHP
try_files $uri $uri/ /index.php$is_args$args;
}
13 changes: 9 additions & 4 deletions globals/wprocket.conf
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,18 @@ location / {
if ($http_cookie ~* "wp_postpass_") { return 418; }

# 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; }
# add_header "Vary" "User-Agent";

# uncomment the following if deemed fit
# 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; }

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

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

add_header "X-Cache" "HIT - WP Rocket Cache";
add_header "X-Cache" "HIT - Desktop";
add_header "X-CF-Powered-By" "WP Rocket";
add_header "Vary" "Cookie";
# include "globals/hsts.conf";

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

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

add_header "X-Cache" "HIT - Mobile - WP Rocket Cache";
add_header "X-Cache" "HIT - Mobile";
add_header "X-CF-Powered-By" "WP Rocket";
add_header "Vary" "User-Agent, Cookie";
# include "globals/hsts.conf";

expires modified 30m;
Expand Down
47 changes: 47 additions & 0 deletions sites-available/dev.example.com.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
server {
listen 80;
listen 443 ssl http2;
server_name dev.example.com;
index index.php;

# Replace the path with the actual path to WordPress core files
root /home/dev/sites/dev.example.com/public;

# ssl_certificate "/etc/letsencrypt/live/dev.example.com/fullchain.pem";
# ssl_certificate_key "/etc/letsencrypt/live/dev.example.com/privkey.pem";

# access_log off;
access_log /var/log/nginx/dev-example.com-access.log;
error_log /var/log/nginx/dev-example.com-error.log;
# error_log /var/log/nginx/dev-example.com-error.log debug;

include "globals/restrictions.conf";

location ~* \.(?:css|js|jpg|jpeg|png|gif|ico|svg|ttf|eot|woff|otf)$ { expires max; try_files $uri @prod; }

location @prod {
proxy_pass https://0.0.0.0;

proxy_set_header Host "www.example.com";

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;

include fastcgi.conf;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors on;
fastcgi_pass fpm-dev;
}

# The rewrite magic
location / { try_files $uri $uri/ /index.php$is_args$args; }
# include "globals/wpsc.conf";
# include "globals/wprocket.conf";
}

0 comments on commit 144e014

Please sign in to comment.