工作 Nginx fastcgi_cache php-fpm 缓存和静态文件缓存配置?

p4g*_*uru 7 nginx cache php-fpm mariadb

Nginx wiki 对如何使用 php-fpm 和 fastcgi_caching 正确设置 nginx 的解释非常模糊,用于具有 cookie 的站点,即 wordpress、drupal、vbulletin 等。

我从http://vbtechsupport.com/796/下载了一个名为 centmin 的修改过的 nginx bash shell 安装脚本,同时它安装了 nginx v1.0.2、php 5.3.6 php-fpm、mariadb 5.2.6 mysql、memcached 1.4.5 服务器并通过shell脚本自动进行siege benchmark,它缺少设置fastcgi_caching以缓存php的配置参数。

它还缺乏为本地服务的文件缓存静态文件的设置。当静态文件驻留在同一磁盘上时,对它们使用 proxy_cache 有什么意义吗?

任何人都得到了一些提示和信息链接,以阅读有关正确设置 php (php-fpm) fastcgi_caching 以及缓存本地驻留静态文件的教程?

谢谢

Kro*_*mey 6

当静态文件驻留在同一磁盘上时,对它们使用 proxy_cache 有什么意义吗?

不,没有。无论哪种方式,它都是对静态文件的磁盘访问。

任何人都得到了一些提示和信息链接,以阅读有关正确设置 php (php-fpm) fastcgi_caching 以及缓存本地驻留静态文件的教程?

看看那里的各种 proxy_caching 教程,尤其是那些从 Apache 代理 WordPress 的教程——fastcgi_caching 几乎是相同的,对于 proxy_caching 几乎毫无疑问也同样适用于 fastcgi_caching。

实际上,我现在正在自己解决这个完全相同的问题。到目前为止,除了考虑 cookie 之外,我已经让它工作了,但这只是if为 fastcgi_cache_key 指令设置附加变量的一系列简单指令。这个页面应该对你非常有用;只需跳到 proxy_caching 配置并将所有这些 proxy_* 指令更改为 fastcgi_* (这是我一直在关注的,但要注意if 是邪恶的,不应驻留在 location 指令中......)。

当我完全解决了自己的问题后,我会将其发布在我的博客上(链接在我的个人资料中;如果我将该链接放在我的帖子中,我会再次遇到麻烦)。真的很遗憾,现在还没有任何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;
Run Code Online (Sandbox Code Playgroud)

这与我在 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;
Run Code Online (Sandbox Code Playgroud)