Nginx FastCGI WordOps Equivalent Code for caching
-
Nginx Fastcgi configuration needed for wordops with flyingpress for mobile and desktop version.
- Mobile, Desktop are separated by user-agent. One is flying press, another is specific content for mobile plugins.
- Second, if i add this line in this code, i believe .htaccess file removes all specific content for mobile file. User detection is by flyingpress in that case and get the page according to the rule. Not sure though.
add_filter( 'scfm_add_mobile_query_string', '__return_false' );I have asked in the your website support to give nginx fastcgi equivalent code. You still dont give that code. So, i cant test it in nginx. Meaning user-agent detection with specific content for mobile with flyingpress or without flyingpress and so both page can be cached perfectly.
Actually I cant test your plugin in nginx because nginx is not detecting only desktop or mobile version of cache. I need to bypass it. Here .htaccess file so i can implement same logic in nginx.# GZIP compression for text files: HTML, CSS, JS, Text, XML, fonts
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/font-woff2
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE font/woff
AddOutputFilterByType DEFLATE font/woff2
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
SetEnvIfNoCase Request_URI \.gz$ no-gzip
</IfModule>
# Response headers for cached .html.gz pages
<FilesMatch "\.html\.gz$">
<IfModule mod_headers.c>
Header set Content-Encoding "gzip"
Header set Content-Type "text/html; charset=UTF-8"
Header set Cache-Tag "tshop.virginprotector.com"
Header set CDN-Cache-Control "max-age=2592000"
Header set Cache-Control "public"
Header set x-flying-press-cache "HIT"
Header set x-flying-press-source "Web Server"
</IfModule>
# Fallback when mod_headers is not available
<IfModule mime_module>
AddType text/html; charset=UTF-8 .gz
AddEncoding gzip .gz
</IfModule>
</FilesMatch>
# Start rewrite requests to cache if found
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Block direct access to .html.gz files
RewriteCond %{THE_REQUEST} "/wp-content/cache/flying-press/.*\.html\.gz" [NC]
RewriteRule ^ - [F]
# Set mobile caching flag to 1 if mobile caching is enabled
RewriteRule ^ - [E=MOBILE_CACHING_FLAG:1]
# Serve mobile cache if the request is from a mobile device and mobile caching is enabled
RewriteCond %{REQUEST_METHOD} GET|HEAD
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP:Cookie} =""
RewriteCond %{REQUEST_URI} !^/(wp-(?:admin|login|register|comments-post|cron|json))/ [NC]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/flying-press/%{HTTP_HOST}%{REQUEST_URI}/index-mobile.html.gz -f
RewriteCond %{ENV:MOBILE_CACHING_FLAG} =1
RewriteRule ^(.*)$ wp-content/cache/flying-press/%{HTTP_HOST}%{REQUEST_URI}/index-mobile.html.gz [L]
# Serve desktop cache if the request is not from a mobile device or if mobile caching is disabled
RewriteCond %{REQUEST_METHOD} GET|HEAD
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP:Cookie} =""
RewriteCond %{REQUEST_URI} !^/(wp-(?:admin|login|register|comments-post|cron|json))/ [NC]
RewriteCond %{HTTP_USER_AGENT} "!(android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile)" [NC,OR]
RewriteCond %{ENV:MOBILE_CACHING_FLAG} !=1
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/flying-press/%{HTTP_HOST}%{REQUEST_URI}/index.html.gz -f
RewriteRule ^(.*)$ wp-content/cache/flying-press/%{HTTP_HOST}%{REQUEST_URI}/index.html.gz [L]
</IfModule>
# End rewrite requests to cache
# END FlyingPress
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
# BEGIN Specific Content For Mobile
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} Mobile|Android|Silk/|Kindle|BlackBerry|Opera\ Mini|Opera\ Mobi [NC]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !scfm-mobile
RewriteCond %{QUERY_STRING} !wc-ajax
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://%{HTTP_HOST}%{REQUEST_URI}\?%{QUERY_STRING}\&scfm-mobile=1 [L,NS,R=301]
RewriteCond %{HTTP_USER_AGENT} Mobile|Android|Silk/|Kindle|BlackBerry|Opera\ Mini|Opera\ Mobi [NC]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} !scfm-mobile
RewriteCond %{QUERY_STRING} !wc-ajax
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{REQUEST_URI} !\.
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://%{HTTP_HOST}%{REQUEST_URI}\?scfm-mobile=1 [L,NS,R=301]
</IfModule>
# END Specific Content For MobileI want my nginx to be scalable as possible without overhead of going every request going to wordpress.
The topic ‘Nginx FastCGI WordOps Equivalent Code for caching’ is closed to new replies.