|
| 1 | +# To improve the perf, we may use open_file_cache |
| 2 | +# ref: https://nginx.org/r/open_file_cache |
| 3 | +# open_file_cache max=1000; |
| 4 | +# open_file_cache_valid 60s; |
| 5 | +# open_file_cache_min_uses 2; |
| 6 | +# open_file_cache_errors off; |
| 7 | + |
| 8 | +location / { |
| 9 | + # requires server support |
| 10 | + # gzip_static on; |
| 11 | + |
| 12 | + error_page 418 = @cachemiss; |
| 13 | + error_page 419 = @mobileaccess; |
| 14 | + recursive_error_pages on; |
| 15 | + |
| 16 | + # bypass POST requests |
| 17 | + if ($request_method = POST) { return 418; } |
| 18 | + |
| 19 | + # uncommenting the following degrades the performance on certain sites. YMMV |
| 20 | + # if ($query_string != "") { return 418; } |
| 21 | + |
| 22 | + # bypass cache for common query strings |
| 23 | + if ($arg_s != "") { return 418; } # search query |
| 24 | + if ($arg_p != "") { return 418; } # request a post / page by ID |
| 25 | + if ($arg_amp != "") { return 418; } # amp test |
| 26 | + if ($arg_preview = "true") { return 418; } # preview post / page |
| 27 | + if ($arg_ao_noptimize != "") { return 418; } # support for Autoptimize plugin |
| 28 | + |
| 29 | + if ($http_cookie ~* "wordpress_logged_in_") { return 418; } |
| 30 | + if ($http_cookie ~* "comment_author_") { return 418; } |
| 31 | + if ($http_cookie ~* "wp_postpass_") { return 418; } |
| 32 | + |
| 33 | + # 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 | + |
| 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 | + try_files "/wp-content/cache/cache-enabler/$host${uri}index.html" $uri $uri/ /index.php$is_args$args; |
| 39 | + |
| 40 | + #--> all the following would apply, only if the request hits the cache |
| 41 | + |
| 42 | + add_header "X-Cache" "HIT - Cache Enabler"; |
| 43 | + # include "globals/hsts.conf"; |
| 44 | + |
| 45 | + # expires modified 30m; |
| 46 | + expires 30m; |
| 47 | + add_header "Cache-Control" "must-revalidate"; |
| 48 | + |
| 49 | + # For proxies |
| 50 | + # add_header "Cache-Control" "s-maxage=3600"; |
| 51 | +} |
| 52 | + |
| 53 | +location @mobileaccess { |
| 54 | + # try_files $uri $uri/ /index.php$is_args$args; |
| 55 | + try_files "/wp-content/cache/supercache/$host${uri}index$https_suffix-mobile.html" $uri $uri/ /index.php$is_args$args; |
| 56 | + |
| 57 | + add_header "X-Cache" "HIT - Mobile - Cache Enabler"; |
| 58 | + # include "globals/hsts.conf"; |
| 59 | + |
| 60 | + # expires modified 30m; |
| 61 | + expires 30m; |
| 62 | + add_header "Cache-Control" "must-revalidate"; |
| 63 | + |
| 64 | + # For proxies |
| 65 | + # add_header "Cache-Control" "s-maxage=3600"; |
| 66 | +} |
| 67 | + |
| 68 | +location @cachemiss { |
| 69 | + try_files $uri $uri/ /index.php$is_args$args; |
| 70 | +} |
0 commit comments