Nginx的Xcaching状态翻转命中和过期的WordPress网站(testingPHP文件确定)

我有一个WordPress网站的nginxcaching设置,它正在nginx头状态x-cache: HITx-cache: EXPIRED之间翻转x-cache: EXPIRED看似随机:

 C:\Users\curl-7.48>curl -I http://example.com HTTP/1.1 200 OK Server: nginx/1.8.0 Date: Sun, 03 Apr 2016 14:15:15 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.5.9-1ubuntu4.14 X-Cached: Sun, 03 Apr 2016 14:15:12 GMT Set-Cookie: PHPSESSID=vfuo4s72b2ffulacumgu9aidf0; path=/ Link: <http://example.com/wp-json/>; rel="https://api.w.org/" Link: <http://example.com/>; rel=shortlink Z_LOCATION: PHP MAIN URI: /index.php X-Cache: HIT C:\Users\curl-7.48>curl -I http://example.com HTTP/1.1 200 OK Server: nginx/1.8.0 Date: Sun, 03 Apr 2016 14:15:17 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.5.9-1ubuntu4.14 X-Cached: Sun, 03 Apr 2016 14:15:16 GMT Set-Cookie: PHPSESSID=fbd37bsvi27cd3hcmrcg4lsio6; path=/ Link: <http://example.com/wp-json/>; rel="https://api.w.org/" Link: <http://example.com/>; rel=shortlink Z_LOCATION: PHP MAIN URI: /index.php X-Cache: EXPIRED C:\Users\curl-7.48>curl -I http://example.com HTTP/1.1 200 OK Server: nginx/1.8.0 Date: Sun, 03 Apr 2016 14:15:46 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive X-Powered-By: PHP/5.5.9-1ubuntu4.14 X-Cached: Sun, 03 Apr 2016 14:15:43 GMT Set-Cookie: PHPSESSID=dkngc066edc1apnogulga1mtg4; path=/ Link: <http://example.com/wp-json/>; rel="https://api.w.org/" Link: <http://example.com/>; rel=shortlink Z_LOCATION: PHP MAIN URI: /index.php X-Cache: HIT 

我也有一个简单的time.php脚本,总是显示命中: <?php echo time(); ?> <?php echo time(); ?>

 C:\Users\curl-7.48\bin>curl -I http://example.com/time.php HTTP/1.1 200 OK Server: nginx/1.8.0 Date: Sun, 03 Apr 2016 14:26:17 GMT Content-Type: text/html Connection: keep-alive X-Powered-By: PHP/5.5.9-1ubuntu4.14 Z_LOCATION: PHP MAIN URI: /time.php X-Cache: HIT 

问题请:

  1. 我caching到/ dev / shm / nginx。 任何发生什么指针和如何发现故障(内存使用情况良好,有没有内存页面交换到磁盘,索引节点是好的)?

  2. 这是否与我的PHP应用程序返回头强迫Nginx不caching? 任何方式来检测这个? 我不能看到任何标题,这在CURL输出中说(除非我失去了一些东西)?

  3. 请问fastcgi_pass php;的sorting问题fastcgi_pass php; 应该在位置的开始还是结束location ~ \.php$ block?

  4. 另外,如何find/dev/shm/nginx time.phpcaching页面的实际文件(有很多第一级目录0x0-0xf ,然后是第二个目录0x00 to 0xff )?

  5. 在运行fatrace我看不到/ dev / shm / nginx正在被读取 – 我错过了什么吗? nginxcaching最近读取文件到本地内存存储?

  6. 我设置caching日志logging为我的网页没有得到从caching服务。但nginx实际上是caching文件 ,看到我得到很多的"GET /all/?source=p1& HTTP/1.1" BYPASS"GET /video/aab HTTP/1.1" EXPIRED条目,这是相关的吗?

我的nginxconfiguration如下:

 http { client_max_body_size 100m; proxy_connect_timeout 15s; proxy_send_timeout 15s; proxy_read_timeout 15s; fastcgi_send_timeout 15s; fastcgi_read_timeout 15s; fastcgi_buffer_size 64k; fastcgi_buffers 32 32k; fastcgi_cache_path /dev/shm/nginx levels=1:2 keys_zone=MYCACHE:512m max_size=4096m inactive=120m; fastcgi_cache_key "$scheme$request_method$host$request_uri"; server { server_name example.com; root /home/example/public_html/; index index.php; access_log /home/example/logs/access.log; error_log /home/example/logs/error.log; # 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; } 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_cache_valid 200 120m; fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_ignore_headers Cache-Control Expires Set-Cookie; fastcgi_cache MYCACHE; 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; fastcgi_pass php; } location ~ /purge(/.*) { fastcgi_cache_purge MYCACHE "$scheme$request_method$host$1"; } } }