Advertisement
Fany_VanDaal

Vymazlení pro WP Rocket

Feb 15th, 2022
1,084
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.16 KB | None
  1. # Nutno nastavit:
  2. # Cache key: $scheme$request_method$host$rocket_mobile_detection$request_uri
  3. # Cache size: 512
  4. # Cache timeout: 6 hodin
  5. # Disable caching for locations (! pozor na české názvy stránek !):
  6. # /wp-admin.*
  7. # /feed.*
  8. # /index.php
  9. # /[a-z0-9_-]+-sitemap([0-9]+)?.xml
  10. # /sitemap(_index)?.xml
  11. # /wp-comments-popup.php
  12. # /wp-links-opml.php
  13. # /wp-locations.php
  14. # /wp-.*.php
  15. # /xmlrpc.php
  16. # /wp-app.php
  17. # /wp-login.php
  18. # /wp-register.php
  19. # /wp-mail.php
  20. # /shop.*
  21. # /cart.*
  22. # /checkout.*
  23. # /my-account.*
  24.  
  25. gzip on;
  26. gzip_comp_level 9;
  27. gzip_http_version 1.0;
  28. gzip_proxied any;
  29. gzip_min_length 1100;
  30. gzip_buffers 16 8k;
  31. gzip_types text/plain text/html text/css application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript image/x-icon image/bmp image/svg+xml;
  32. gzip_disable "MSIE [1-6].(?!.*SV1)";
  33. gzip_vary on;
  34.  
  35. ###################################################################################################
  36. # Rocket-Nginx
  37. #
  38. # Rocket-Nginx is a NGINX configuration to speedup your WordPress
  39. # website with the cache plugin WP-Rocket (http://wp-rocket.me)
  40. #
  41. # Author: Maxime Jobin
  42. # URL: https://github.com/maximejobin/rocket-nginx
  43. #
  44. # Tested with WP-Rocket version: 3.6.0.1
  45. # Tested with NGINX: 1.19 (mainline)
  46. #
  47. # Version 2.1.1
  48. #
  49. ###################################################################################################
  50.  
  51. # Add debug information into header
  52. set $rocket_debug 1;
  53.  
  54. ###################################################################################################
  55. # Do not alter theses values
  56. #
  57. set $rocket_bypass 1;               # Should NGINX bypass WordPress and call cache file directly ?
  58. set $rocket_encryption "";          # Is GZIP accepted by client ?
  59. set $rocket_file "";                # Filename to use
  60. set $rocket_is_bypassed "No";       # Header text added to check if the bypass worked or not. Header: X-Rocket-Nginx-Serving-Static
  61. set $rocket_reason "";              # Reason why cache file was not used. If cache file is used, what file was used
  62. set $rocket_https_prefix "";        # HTTPS prefix to use when cached files are using HTTPS
  63. set $rocket_hsts 0;                 # Is HSTS is off (0) by default. Will be turned on (1) if request is HTTPS
  64.  
  65. # HSTS value
  66. set $rocket_hsts_value "max-age=31536000; includeSubDomains";
  67.  
  68. ###################################################################################################
  69. # PAGE CACHE
  70. #
  71.  
  72. # Is GZIP accepted by client ?
  73. if ($http_accept_encoding ~ gzip) {
  74.     set $rocket_encryption "_gzip";
  75. }
  76.  
  77. # Is Brotli accepted by client ?
  78. if ($http_accept_encoding ~ br) {
  79.     set $rocket_encryption "";
  80. }
  81.  
  82. # Is SSL request ?
  83. if ($https = "on") {
  84.     set $rocket_https_prefix "-https";
  85.     set $rocket_hsts 1;
  86. }
  87.  
  88. # If HSTS is disabled, unset HSTS set for Rocket-Nginx configuration
  89. if ($rocket_hsts = "0") {
  90.     set $rocket_hsts_value "";
  91. }
  92.  
  93. # File/URL to return IF we must bypass WordPress
  94. # Desktop: index.html or index-https.html
  95. # Mobile:  index-mobile.html or index-mobile-https.html
  96. set $rocket_end "/cache/wp-rocket/$http_host${request_uri}index$rocket_https_prefix.html$rocket_encryption";
  97. set $rocket_url "/wp-content$rocket_end";
  98. set $rocket_file "$document_root/wp-content$rocket_end";
  99. set $rocket_mobile_detection "$document_root/wp-content/cache/wp-rocket/$http_host${request_uri}.mobile-active";
  100.  
  101. # Do not bypass if it's a POST request
  102. if ($request_method = POST) {
  103.     set $rocket_bypass 0;
  104.     set $rocket_reason "POST request";
  105. }
  106.  
  107. # Do not bypass if arguments are found (e.g. ?page=2)
  108. if ($is_args) {
  109.     set $rocket_bypass 0;
  110.     set $rocket_reason "Arguments found";
  111. }
  112.  
  113. # Do not bypass if the site is in maintenance mode
  114. if (-f "$document_root/.maintenance") {
  115.     set $rocket_bypass 0;
  116.     set $rocket_reason "Maintenance mode";
  117. }
  118.  
  119. # Do not bypass if one of those cookie if found
  120. # wordpress_logged_in_[hash] : When a user is logged in, this cookie is created (we'd rather let WP-Rocket handle that)
  121. # wp-postpass_[hash] : When a protected post requires a password, this cookie is created.
  122. if ($http_cookie ~* "(wp\-postpass_|woocommerce_items_in_cart|woocommerce_cart_hash|wptouch_switch_toogle|comment_author_|comment_author_email_)") {
  123.     set $rocket_bypass 0;
  124.     set $rocket_reason "Cookie";
  125. }
  126.  
  127. if (-f "$rocket_mobile_detection") {
  128.     set $rocket_bypass 0;
  129.     set $rocket_reason "Specific mobile cache activated";
  130. }
  131.  
  132. # Do not bypass if the cached file does not exist
  133. if (!-f "$rocket_file") {
  134.     set $rocket_bypass 0;
  135.     set $rocket_reason "File not cached";
  136. }
  137.  
  138. # If the bypass token is still on, let's bypass WordPress with the cached URL
  139. if ($rocket_bypass = 1) {
  140.     set $rocket_is_bypassed "Yes";
  141.     set $rocket_reason "$rocket_url";
  142. }
  143.  
  144. # Clear variables if debug is not needed
  145. if ($rocket_debug = 0) {
  146.     set $rocket_reason "";
  147.     set $rocket_file "";
  148. }
  149.  
  150. # If the bypass token is still on, rewrite according to the file linked to the request
  151. if ($rocket_bypass = 1) {
  152.     rewrite .* "$rocket_url" last;
  153. }
  154.  
  155. # Add header to HTML cached files
  156. location ~ /wp-content/cache/wp-rocket/.*html$ {
  157.     etag on;
  158.     add_header Vary "Accept-Encoding, Cookie";
  159.     add_header Cache-Control "no-cache, no-store, must-revalidate";
  160.     add_header X-Rocket-Nginx-Serving-Static $rocket_is_bypassed;
  161.     add_header X-Rocket-Nginx-Reason $rocket_reason;
  162.     add_header X-Rocket-Nginx-File $rocket_file;
  163.     add_header Strict-Transport-Security "$rocket_hsts_value";
  164. }
  165.  
  166. # Do not gzip cached files that are already gzipped
  167. location ~ /wp-content/cache/wp-rocket/.*_gzip$ {
  168.     etag on;
  169.     gzip off;
  170.     types {}
  171.     default_type text/html;
  172.     add_header Content-Encoding gzip;
  173.     add_header Vary "Accept-Encoding, Cookie";
  174.     add_header Cache-Control "no-cache, no-store, must-revalidate";
  175.     add_header X-Rocket-Nginx-Serving-Static $rocket_is_bypassed;
  176.     add_header X-Rocket-Nginx-Reason $rocket_reason;
  177.     add_header X-Rocket-Nginx-File $rocket_file;
  178.     add_header Strict-Transport-Security "$rocket_hsts_value";
  179. }
  180.  
  181. # Debug header (when file is not cached)
  182. add_header X-Rocket-Nginx-Serving-Static $rocket_is_bypassed;
  183. add_header X-Rocket-Nginx-Reason $rocket_reason;
  184. add_header X-Rocket-Nginx-File $rocket_file;
  185.  
  186. # No HSTS header added here. We suppose it's correctly added in the site configuration
  187.  
  188. ###################################################################################################
  189. # BROWSER CSS CACHE
  190. #
  191. location ~* \.css$ {
  192.     etag on;
  193.     gzip_vary on;
  194.     expires 30d;
  195.  
  196. }
  197.  
  198. ###################################################################################################
  199. # BROWSER JS CACHE
  200. #
  201. location ~* \.js$ {
  202.     etag on;
  203.     gzip_vary on;
  204.     expires 30d;
  205.  
  206. }
  207.  
  208. #### Imagify #########
  209. location ~* ^(/.+)\.(jpg|jpeg|jpe|png|gif)$ {
  210.     add_header Vary Accept;
  211.     etag on;
  212.     expires 30d;
  213.  
  214.     if ($http_accept ~* "webp"){
  215.         set $imwebp A;
  216.     }
  217.     if (-f $request_filename.webp) {
  218.         set $imwebp  "${imwebp}B";
  219.     }
  220.     if ($imwebp = AB) {
  221.         rewrite ^(.*) $1.webp;
  222.     }
  223. }
  224.  
  225. ###################################################################################################
  226. # BROWSER MEDIA CACHE
  227. #
  228. location ~* \.(ico|svg|eot|otf|woff|woff2|ttf|ogg)$ {
  229.     etag on;
  230.     expires 30d;
  231.  
  232. }
  233.  
  234. location ~ / {
  235.     try_files $uri $uri/ /index.php ;
  236. }
  237.  
  238. # WORDPRESS PERMALINKS
  239. if (!-e $request_filename) {
  240.     rewrite ^(.+)$ /index.php last;
  241. }
Advertisement
RAW Paste Data Copied
Advertisement