AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 754476
Accepted
morleyc
morleyc
Asked: 2016-02-07 11:02:46 +0800 CST2016-02-07 11:02:46 +0800 CST 2016-02-07 11:02:46 +0800 CST

用于登录 WordPress 用户的 Nginx 缓存页面(并向访问者显示管理栏!)

  • 772

我已经在 WordPress 中设置了带有缓存的 nginx。

我正在使用https://wordpress.org/plugins/nginx-helper/,但是登录页面似乎在不应该被缓存时被缓存(因此显示了登录栏)。

一些未登录的访问者(也没有任何 cookie/浏览器缓存)正在查看登录栏(如果他们点击栏中的任何内容,则会将他们重定向到登录页面)。

在此处输入图像描述

此外,当我单击 WordPress 中的清除缓存按钮时,页面仍然提供并显示为XCache HIT......真正清除的唯一方法是通过rm -rf /dev/shm/nginx.

我确实安装了以下模块:

nginx version: nginx/1.8.0
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' 
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log 
--error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body 
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi 
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi
--with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module
--with-http_stub_status_module --with-http_realip_module 
--with-http_auth_request_module --with-http_addition_module
--with-http_geoip_module --with-http_gzip_static_module
--with-http_image_filter_module --with-http_spdy_module 
--with-http_sub_module --with-http_xslt_module
--add-module=/build/buildd/nginx-1.8.0/debian/modules/headers-more-nginx-module 
--add-module=/build/buildd/nginx-1.8.0/debian/modules/nginx-auth-pam
--add-module=/build/buildd/nginx-1.8.0/debian/modules/nginx-cache-purge 
--add-module=/build/buildd/nginx-1.8.0/debian/modules/nginx-echo
--add-module=/build/buildd/nginx-1.8.0/debian/modules/ngx-fancyindex 
--add-module=/build/buildd/nginx-1.8.0/debian/modules/nginx-lua
--add-module=/build/buildd/nginx-1.8.0/debian/modules/nginx-upload-progress 
--add-module=/build/buildd/nginx-1.8.0/debian/modules/nginx-upstream-fair
--add-module=/build/buildd/nginx-1.8.0/debian/modules/ngx_http_substitutions_filter_module 
--add-module=/build/buildd/nginx-1.8.0/debian/modules/ngx_pagespeed

知道我的配置有什么问题吗?

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
        worker_connections 1024;
        multi_accept on;
}

http {
        geoip_country /usr/local/share/GeoIP/GeoIP.dat;
        geoip_city /usr/local/share/GeoIP/GeoLiteCity.dat;

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;

        client_max_body_size 300m;
        proxy_send_timeout 300;
        proxy_read_timeout 300;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;

        gzip on;
        gzip_disable "msie6";


        # Upstream to abstract backend connection(s) for PHP.
        upstream php {
               server 127.0.0.1:9000;
        }

        include /etc/nginx/conf.d/*.conf;

        fastcgi_cache_path /dev/shm/nginx levels=1:2 keys_zone=WPCACHE:384m max_size=3072m inactive=480m;
        fastcgi_cache_key "$scheme$request_method$host$request_uri";

        server {
            server_name mysite.com;
            root /home/mysite/public_html/;
            index index.php;

            access_log /home/mysite/logs/access.log;
            error_log  /home/mysite/logs/error.log;

            fastcgi_cache_use_stale error timeout invalid_header http_500;
            fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

            # Rules to work out when cache should or should not be used
            set $skip_cache 0;
            # POST requests and urls with a query string should always go to PHP

            if ($request_method = POST) {
                set $skip_cache 1;
            }

            if ($query_string != "") {
                set $skip_cache 1;
            }

            # Don't cache uris containing the following segments
            if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
                set $skip_cache 1;
            }

            # Don't use the cache for logged in users or recent commenters
            if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
                set $skip_cache 1;
            }

            location = /favicon.ico {
                log_not_found off;
                access_log off;
            }

            location / {
                try_files $uri $uri/ /index.php?$args;
            }

            # Add trailing slash to */wp-admin requests.
            rewrite /wp-admin$ $scheme://$host$uri/ permanent;

            location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_pass php;

                fastcgi_cache WPCACHE;
                fastcgi_cache_valid 200 480m;


                fastcgi_cache_methods GET HEAD;
                fastcgi_cache_bypass $skip_cache;
                fastcgi_no_cache $skip_cache;

                #more_clear_headers Server; more_clear_headers "Pragma";
                add_header Z_LOCATION "PHP MAIN"; add_header URI $uri; # DEBUG
                add_header X-Cache $upstream_cache_status;
            }

            location ~ /purge(/.*) {
                fastcgi_cache_purge WPCACHE "$scheme$request_method$host$1";
            }

            location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
                access_log off;
                log_not_found off;
                expires max;
            }

            location = /robots.txt {
                access_log off;
                log_not_found off;
            }

            location ~ /\. {
                deny  all;
                access_log off;
                log_not_found off;
            }
        }   
}
nginx
  • 1 1 个回答
  • 2701 Views

1 个回答

  • Voted
  1. Best Answer
    Tim
    2016-02-07T12:48:49+08:002016-02-07T12:48:49+08:00

    该配置看起来非常熟悉 - 我在另一个线程中发布了大部分内容:) 唉,它缺少一个重要部分。

    location = /wp-login.php {
      fastcgi_keep_conn on;
      fastcgi_intercept_errors on;
      fastcgi_pass   php;
      include        fastcgi_params;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
      # No caching
      more_clear_headers "Cache-Control";
      add_header Cache-Control "private, max-age=0, no-cache, no-store";
      more_clear_headers "Expires";
    }
    

    此外,Nginx Helper 无法清除缓存。我花了 AGES 试图让它工作,但它只是没有。我也无法让Nginx 缓存插件工作。

    Nginx 缓存更新

    来自评论中的@rafa:问题是 nginx-helper 有一个硬编码路径,用于缓存文件位于 /var/run/nginx-cache 下,并且 OP 的配置指示 /dev/shm/nginx 的路径缓存文件。我刚刚将我的 fastcgi_cache_path 更改为“正确”路径,并且 nginx-cache 工作

    • 1

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve