我正在尝试让W3 Total Cache将URL重写为缩小的文件。我已经试过了我能找到的每一个教程,但我似乎都做不好。我一直收到一个W3 Total Cache错误,上面说:
It appears Minify URL rewriting is not working. If using apache, verify that the server configuration allows .htaccess. Or if using nginx verify all configuration files are included in the main configuration fail (and that you have reloaded / restarted nginx).
我的nginx配置文件如下:
nginx.conf in /etc/nginx/user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
access_log off;
sendfile on;
keepalive_timeout 20;
client_max_body_size 15m;
upstream php {
server unix:/dev/shm/php-fpm-www.sock;
}
include /etc/nginx/conf.d/default.conf
}
此文件链接到
/etc/nginx/conf.d/default.conf:
server {
server_name mydomain.com www.mydomain.com;
listen 8080;
root /var/www/;
index index.php index.html index.htm;
include /var/www/nginx.conf;
include /etc/nginx/conf.d/wp.conf;
}
此文件本身链接到
/etc/nginx/conf.d/wp.conf 如下所示:
error_page 404 = @wordpress;
log_not_found off;
location / {
try_files $uri $uri/ /index.php?args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
location @wordpress {
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
include fastcgi_params;
fastcgi_param SCRIPT_NAME /index.php;
}
location ~ \\.php$ {
fastcgi_max_temp_file_size 1M;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_index index.php;
fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
try_files $uri @wordpress;
}
/etc/nginx/conf.d/default.conf 还链接到
nginx.conf 在我的Wordpress根文件夹中创建了文件W3 Total Cache,如下所示:
# BEGIN W3TC Minify cache
location ~ /wp-content/cache/minify.*\\.js$ {
types {}
default_type application/x-javascript;
expires modified 604800s;
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=604800, public";
}
location ~ /wp-content/cache/minify.*\\.css$ {
types {}
default_type text/css;
expires modified 604800s;
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=604800, public";
}
location ~ /wp-content/cache/minify.*js\\.gzip$ {
gzip off;
types {}
default_type application/x-javascript;
expires modified 604800s;
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=604800, public";
add_header Content-Encoding gzip;
}
location ~ /wp-content/cache/minify.*css\\.gzip$ {
gzip off;
types {}
default_type text/css;
expires modified 604800s;
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=604800, 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/javascri$
location ~ \\.(css|htc|js|js2|js3|js4)$ {
expires 604800s;
add_header Pragma "public";
add_header Cache-Control "max-age=604800, 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$
expires 604800s;
add_header Pragma "public";
add_header Cache-Control "max-age=604800, public";
add_header Link "<$scheme://$host$uri>; rel=\\"canonical\\"";
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/mini$
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.ph$
# 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 ($http_cookie ~* "(comment_author|wp\\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_swit$
set $w3tc_rewrite 0;
}
set $w3tc_enc "";
if ($http_accept_encoding ~ gzip) {
set $w3tc_enc _gzip;
}
set $w3tc_ext "";
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.html$w3tc_enc$
set $w3tc_ext .html;
}
if (-f "$document_root/wp-content/cache/page_enhanced/$http_host/$request_uri/_index.xml$w3tc_enc"$
set $w3tc_ext .xml;
}
if ($w3tc_ext = "") {
set $w3tc_rewrite 0;
}
if ($w3tc_rewrite = 1) {
rewrite .* "/wp-content/cache/page_enhanced/$http_host/$request_uri/_index$w3tc_ext$w3tc_enc" $
}
# END W3TC Page Cache core
# BEGIN W3TC CDN
location ~ \\.(ttf|otf|eot|woff)$ {
add_header Access-Control-Allow-Origin "*";
}
# END W3TC CDN
在我的终端中从nano复制粘贴时,有些行并没有完全显示在屏幕上,但这些都是标准的W3总缓存设置,我没有碰它们。他们应该没事。
我在端口8080上安装了nginx,在端口80上安装了varnish,安装了php5 fpm和MySQL。如果有人能在这方面帮助我,那就太棒了。如果您需要更多信息、配置文件等,请告诉我。