有效的 Nginx fastcgi_cache php-fpm 缓存和静态文件缓存配置?

有效的 Nginx fastcgi_cache php-fpm 缓存和静态文件缓存配置?

Nginx wiki is very vague with explanation as to how to properly setup nginx with php-fpm with fastcgi_caching for sites which have cookies i.e. wordpress, drupal, vbulletin etc.

I downloaded a modified nginx bash shell install script called centmin from http://vbtechsupport.com/796/ and while it installs nginx v1.0.2, php 5.3.6 php-fpm, mariadb 5.2.6 mysql, memcached 1.4.5 servers and siege benchmark automatically via shell script, it lacks the configuration parameters for setting up fastcgi_caching for caching php.

It also lacks setup for caching static files for locally served files. Is there any point in using proxy_cache for static files when they reside on the same disk ?

Anyone got some tips and info links to info to read up on tutorials for proper setup for php (php-fpm) fastcgi_caching as well as for caching locally residing static files ?

thanks

答案1

Is there any point in using proxy_cache for static files when they reside on the same disk ?

Nope, none. It's disk access to static files either way.

Anyone got some tips and info links to info to read up on tutorials for proper setup for php (php-fpm) fastcgi_caching as well as for caching locally residing static files ?

Take a look at the various proxy_caching tutorials out there, especially those that proxy WordPress from Apache -- the fastcgi_caching is very nearly identical, and what works for proxy_caching will almost undoubtedly work just as well for fastcgi_caching.

实际上,我本人现在也正在研究这个完全相同的问题。到目前为止,除了考虑 cookie 之外,我已经让它正常工作了,但这只是一系列简单的if指令,用于为 fastcgi_cache_key 指令设置其他变量。这一页应该对你非常有用;只需跳到 proxy_caching 配置并将所有 proxy_* 指令更改为 fastcgi_* (这是我一直在遵循的,但要注意if 是邪恶的并且不应驻留在位置指令内......)。

当我完全搞清楚自己的计划后,我会把它发布在我的博客上(链接在我的个人资料中;如果我把这个链接放在我的帖子里,我会再次惹上麻烦)。很遗憾没有,嗯,任何fastcgi_caching 指南已经存在,所以我不能给你指出任何东西除了我的博客(尽管它还没有出现...)。

编辑后添加:这是我当前的 fastcgi_caching 配置。正如我所说,它还没有考虑到 cookie,但实际上它在大多数情况下确实可以按原样运行。

在处理我的 .php 文件的位置块中,我添加了:

#Caching parameters
fastcgi_cache one;
#I use host here to account for the fact that I have multiple WP instances
fastcgi_cache_key $scheme$host$request_uri;

fastcgi_cache_valid  200 302 304 30m;
fastcgi_cache_valid  301 1h;
fastcgi_cache_valid  any 5m;
fastcgi_cache_use_stale error timeout invalid_header updating http_500;

这与我在 http 块中所做的添加相关:

# configure cache log
log_format cache '$remote_addr - $host [$time_local]  '
                 '"$request" $status $upstream_cache_status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';


# Configure cache and temp paths
fastcgi_cache_path /var/cache/nginx levels=1:2
                   keys_zone=one:100m
                   inactive=7d max_size=10g;
fastcgi_temp_path /var/cache/nginx/tmp;

相关内容