nginx W3TC: rewrite rules issue
-
nginx 1.2.7 + WP 3.5.1 + W3TC 0.9.2.8.
Rewrite rules generated by the plugin simply don’t work, server returns 404 after including them in nginx server config. Or maybe I’m doing something wrong?
Here is my nginx.conf:
user www-data; worker_processes 2; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; index index.html index.htm index.php; default_type application/octet-stream; sendfile on; tcp_nopush on; log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log warn; include /etc/nginx/conf.d/*.conf; }
Here is my virtual server config:
server { listen 80; server_name example.com www.example.com; root /var/www/example.com; access_log /var/log/nginx/example.access.log; error_log /var/log/nginx/example.error.log; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php { try_files $uri =404; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } include /var/www/example.com/nginx.conf; }
And finally config generated by W3TC:
# BEGIN W3TC Minify cache location ~ /wp-content/cache/minify.*\.js$ { types {} default_type application/x-javascript; expires modified 2628000s; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=2628000, public"; } location ~ /wp-content/cache/minify.*\.css$ { types {} default_type text/css; expires modified 2628000s; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=2628000, public"; } location ~ /wp-content/cache/minify.*js\.gzip$ { gzip off; types {} default_type application/x-javascript; expires modified 2628000s; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=2628000, public"; add_header Content-Encoding gzip; } location ~ /wp-content/cache/minify.*css\.gzip$ { gzip off; types {} default_type text/css; expires modified 2628000s; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=2628000, public"; add_header Content-Encoding gzip; } # END W3TC Minify cache # BEGIN W3TC Page Cache cache location ~ /wp-content/cache/page_enhanced.*html$ { expires modified 3600s; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; add_header Vary "Accept-Encoding, Cookie"; add_header Pragma "public"; add_header Cache-Control "max-age=3600, public"; } location ~ /wp-content/cache/page_enhanced.*gzip$ { gzip off; types {} default_type text/html; expires modified 3600s; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; add_header Vary "Accept-Encoding, Cookie"; add_header Pragma "public"; add_header Cache-Control "max-age=3600, public"; add_header Content-Encoding gzip; } # END W3TC Page Cache cache # BEGIN W3TC Browser Cache gzip on; gzip_types text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon; location ~ \.(css|htc|js|js2|js3|js4)$ { expires 2628000s; add_header Pragma "public"; add_header Cache-Control "max-age=2628000, public"; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; } location ~ \.(html|htm|rtf|rtx|svg|svgz|txt|xsd|xsl|xml)$ { expires 3600s; add_header Pragma "public"; add_header Cache-Control "max-age=3600, public"; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; try_files $uri $uri/ $uri.html /index.php?$args; } location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$ { expires 31536000s; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; add_header X-Powered-By "W3 Total Cache/0.9.2.8"; } # END W3TC Browser Cache # BEGIN W3TC Minify core rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last; set $w3tc_enc ""; if ($http_accept_encoding ~ gzip) { set $w3tc_enc .gzip; } if (-f $request_filename$w3tc_enc) { rewrite (.*) $1$w3tc_enc break; } rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last; # END W3TC Minify core # BEGIN W3TC Page Cache core set $w3tc_rewrite 1; if ($request_method = POST) { set $w3tc_rewrite 0; } if ($query_string != "") { set $w3tc_rewrite 0; } if ($request_uri !~ \/$) { set $w3tc_rewrite 0; } if ($http_cookie ~* "(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle)") { set $w3tc_rewrite 0; } set $w3tc_enc ""; if ($http_accept_encoding ~ gzip) { set $w3tc_enc _gzip; } if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc") { set $w3tc_rewrite 0; } if ($w3tc_rewrite = 1) { rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc" last; } # END W3TC Page Cache core
Returns 404.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘nginx W3TC: rewrite rules issue’ is closed to new replies.