W3总缓存-将阿帕奇重写转换为Nginx

时间:2013-09-02 作者:Dave

我正在尝试将以下Apache重写转换为Nginx:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} \\/$
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html" [L]
</IfModule>
我所做的是:

# Set a variable to work around the lack of nested conditionals
set $cache_uri $request_uri;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
    set $cache_uri \'no cache\';
}
if ($query_string != "") {
    set $cache_uri \'no cache\';
}

# Don\'t cache uris containing the following segments
if ($request_uri ~* "(\\/wp-admin\\/|\\/xmlrpc.php|\\/wp-(app|cron|login|register|mail)\\.php|wp-.*\\.php|index\\.php|wp\\-comments\\-popup\\.php|wp\\-links\\-opml\\.php|wp\\-locations\\.php)") {
    set $cache_uri "no cache";
 }

# Don\'t use the cache for logged in users or recent commenters
if if ($http_cookie ~* "comment_author|wp\\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle") {
    set $cache_uri \'no cache\';
 }

 # If the cache file does not exist, pass it of to apache for processing
location / {
    try_files /wp-content/cache/page_enhanced/example.com/$cache_uri/_index.html @backend;
}

# Pass off php requests to Apache
location ~* \\.php$ {           
    include /usr/local/etc/nginx/proxypass.conf;
    proxy_pass         http://127.0.0.1:80;
}

# Pass off php requests to Apache
location @backend {
    include /usr/local/etc/nginx/proxypass.conf;
    proxy_pass         http://127.0.0.1:80;
}
我想知道的是我是否遗漏了什么?还是做错了什么?

1 个回复
最合适的回答,由SO网友:Pothi Kalimuthu 整理而成

根据您的评论,以下是W3 Total cache插件中带有“磁盘:增强”页面缓存方法的Nginx Apache堆栈的解决方案。。。

location / {
    error_page 418 = @cachemiss;
    recursive_error_pages on;

    if ($request_method = POST) { return  418; }

    if ($query_string != "") { return 418; }

    if ($request_uri ~* "(\\/wp-admin\\/|\\/xmlrpc.php|\\/wp-(app|cron|login|register|mail)\\.php|wp-.*\\.php|index\\.php|wp\\-comments\\-popup\\.php|wp\\-links\\-opml\\.php|wp\\-locations\\.php)") { return 418; }

    if ($http_cookie ~* "comment_author|wp\\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle") { return 418; }

    try_files "/wp-content/cache/page_enhanced/$host/$uri/_index.html" =418;

    # optional code
    # expires 30m;
    # add_header "X-W3TC-Cache" "HIT :)";
}

location @cachemiss {
    # pass the requests to backend (Apache)

    # optional header
    # add_header "X-W3TC-Cache" "Miss :(";
}

# other directives
# for example
location ~* \\.php$ {
    # pass PHP requests to Apache
}

# another example
location /wp-admin {
    # pass requests to Apache
}
上述解决方案如下the best practices of using an if statement in Nginx 修改后,可正确用于WPSC。我希望这有帮助。

结束

相关推荐

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

我正在尝试让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

W3总缓存-将阿帕奇重写转换为Nginx - 小码农CODE - 行之有效找到问题解决它

W3总缓存-将阿帕奇重写转换为Nginx

时间:2013-09-02 作者:Dave

我正在尝试将以下Apache重写转换为Nginx:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} \\/$
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html" [L]
</IfModule>
我所做的是:

# Set a variable to work around the lack of nested conditionals
set $cache_uri $request_uri;

# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
    set $cache_uri \'no cache\';
}
if ($query_string != "") {
    set $cache_uri \'no cache\';
}

# Don\'t cache uris containing the following segments
if ($request_uri ~* "(\\/wp-admin\\/|\\/xmlrpc.php|\\/wp-(app|cron|login|register|mail)\\.php|wp-.*\\.php|index\\.php|wp\\-comments\\-popup\\.php|wp\\-links\\-opml\\.php|wp\\-locations\\.php)") {
    set $cache_uri "no cache";
 }

# Don\'t use the cache for logged in users or recent commenters
if if ($http_cookie ~* "comment_author|wp\\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle") {
    set $cache_uri \'no cache\';
 }

 # If the cache file does not exist, pass it of to apache for processing
location / {
    try_files /wp-content/cache/page_enhanced/example.com/$cache_uri/_index.html @backend;
}

# Pass off php requests to Apache
location ~* \\.php$ {           
    include /usr/local/etc/nginx/proxypass.conf;
    proxy_pass         http://127.0.0.1:80;
}

# Pass off php requests to Apache
location @backend {
    include /usr/local/etc/nginx/proxypass.conf;
    proxy_pass         http://127.0.0.1:80;
}
我想知道的是我是否遗漏了什么?还是做错了什么?

1 个回复
最合适的回答,由SO网友:Pothi Kalimuthu 整理而成

根据您的评论,以下是W3 Total cache插件中带有“磁盘:增强”页面缓存方法的Nginx Apache堆栈的解决方案。。。

location / {
    error_page 418 = @cachemiss;
    recursive_error_pages on;

    if ($request_method = POST) { return  418; }

    if ($query_string != "") { return 418; }

    if ($request_uri ~* "(\\/wp-admin\\/|\\/xmlrpc.php|\\/wp-(app|cron|login|register|mail)\\.php|wp-.*\\.php|index\\.php|wp\\-comments\\-popup\\.php|wp\\-links\\-opml\\.php|wp\\-locations\\.php)") { return 418; }

    if ($http_cookie ~* "comment_author|wp\\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle") { return 418; }

    try_files "/wp-content/cache/page_enhanced/$host/$uri/_index.html" =418;

    # optional code
    # expires 30m;
    # add_header "X-W3TC-Cache" "HIT :)";
}

location @cachemiss {
    # pass the requests to backend (Apache)

    # optional header
    # add_header "X-W3TC-Cache" "Miss :(";
}

# other directives
# for example
location ~* \\.php$ {
    # pass PHP requests to Apache
}

# another example
location /wp-admin {
    # pass requests to Apache
}
上述解决方案如下the best practices of using an if statement in Nginx 修改后,可正确用于WPSC。我希望这有帮助。

相关推荐

如何启用Keep Alive(保持活动状态)(不访问APACHE)

我正在监视我的网站(faghatseo.com) 看到有关保持活动状态的错误。我在google上搜索了这个问题,作为解决方案,有一个代码<IfModule mod_headers.c> Header set Connection keep-alive </IfModule> 你必须放在.htaccess 按以下方向归档:/public_html/.htaccess当我输入代码时,出现了错误500,我的网站宕机了!内部服务器错误服务器遇到内部错误或配置错误