W3在nginx上使用WordPress时的总缓存减少重写错误

时间:2013-02-15 作者:Nick Rutten

我正在尝试让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。如果有人能在这方面帮助我,那就太棒了。如果您需要更多信息、配置文件等,请告诉我。

2 个回复
SO网友:Christiaan

在Nginx/PHP-FPM可以写入的位置,为您的站点创建一个专门用于W3总缓存配置的文件。将此文件包括在站点的Nginx服务器配置中。然后在“常规设置”页面的“杂项”下,在“Nginx服务器配置文件路径”字段中提供该文件的完整路径。然后,W3TC将知道如何将所需的任何Nginx规则写入该文件。

更改W3TC设置以反映所需的配置。一旦您对设置满意,请重新加载Nginx。您的W3TC配置现在应该可以正常工作了。

SO网友:wp student

只需禁用javascript缩小。我为我的网站做了这件事,它成功了。

结束

相关推荐

自定义固定链接在Nginx+Apache上不起作用

我有个奇怪的情况。。。将nginx设置为与apache一起使用后,我的permalinks无法工作。permalinks在不以“.html”结束时工作,但在以“/”结束时工作ie.:这项工作:justflick。com/new-the-dark-knight-rises-set-photo-2012-01-25。html/汤姆·哈代饰演《黑暗骑士》中的贝恩崛起但这不是:只是弹一下。com/new-the-dark-knight-rises-set-photo-2012-01-25。html这是我对这个网站

W3在nginx上使用WordPress时的总缓存减少重写错误 - 小码农CODE - 行之有效找到问题解决它

W3在nginx上使用WordPress时的总缓存减少重写错误

时间:2013-02-15 作者:Nick Rutten

我正在尝试让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。如果有人能在这方面帮助我,那就太棒了。如果您需要更多信息、配置文件等,请告诉我。

2 个回复
SO网友:Christiaan

在Nginx/PHP-FPM可以写入的位置,为您的站点创建一个专门用于W3总缓存配置的文件。将此文件包括在站点的Nginx服务器配置中。然后在“常规设置”页面的“杂项”下,在“Nginx服务器配置文件路径”字段中提供该文件的完整路径。然后,W3TC将知道如何将所需的任何Nginx规则写入该文件。

更改W3TC设置以反映所需的配置。一旦您对设置满意,请重新加载Nginx。您的W3TC配置现在应该可以正常工作了。

SO网友:wp student

只需禁用javascript缩小。我为我的网站做了这件事,它成功了。

相关推荐

Docker化的Wordpress出现了Nginx代理问题

我有一个停靠的Nginx代理,它位于我的服务器上。我的一个网站是Docker Compose Wordpress网站。它们是单独的容器,必须保持这种状态。When I update my Site Url in the Settings I can still log into my Admin Dashboard, but I cannot reach my actual site. I receive a 502 Gateway Error from Nginx. Nginx服务器块: serv