配置nginx fastcgi cache

1. 创建cache目录

  • mkdir -p /data/nginx/cache

  • chown -R nobody:nobody /data/nginx/cache

2. 在nginx.conf http节点添加

  1. fastcgi_cache_path /data/nginx/cache/fastcgicache levels=1:2 keys_zone=fastcgicache:10m max_size=256m inactive=1m;
  2. fastcgi_cache_key $scheme$request_method$host$request_uri;
  3. fastcgi_cache_valid 200 1m;
  4. fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

3. 配置server节点pc.live.shoahualee.com

  1. server {
  2. ...
  3. set $fastcgi_skipcache 1;
  4. if ($uri ~ "/static") {
  5. set $fastcgi_skipcache 0;
  6. }
  7. location ~ \.php$ {
  8. ...
  9. add_header X-Cache $upstream_cache_status;
  10. fastcgi_cache_lock on;
  11. fastcgi_cache fastcgicache;
  12. fastcgi_cache_bypass $fastcgi_skipcache;
  13. fastcgi_no_cache $fastcgi_skipcache;
  14. ...
  15. }
  16. rewrite "/static(.*)" /caller.php$1;
  17. ...
  18. }

4. 加载配置

nginx -s reload

分类: web

标签:   nginx