jworkman/wordpress-fastcgi-cache
Composer 安装命令:
composer require jworkman/wordpress-fastcgi-cache
包简介
Quick tool utilities to manage a fastcgi cache enabled server
关键字:
README 文档
README
Quick tool utilities to manage a fastcgi cache enabled server
Nginx Configuration
In order to setup Nginx to use fast cgi cache we must configure Nginx in a couple of different places. This plugin assumes that the fast cgi cache will be located in the directory /var/cache/nginxfastcgi
So first lets make that directory on the server:
mkdir -p /var/cache/nginxfastcgi
Also create a global directory in your nginx etc directory:
mkdir /etc/nginx/global
Make sure you set the ownership to whatever user your nginx user is running under. Run the following and replace owner_name with the username that nginx uses to run under:
chown -R owner_name:owner_name /var/cache/nginxfastcgi
After that lets create a file called /etc/nginx/global/wordpress_cache.conf and place the below code inside of it. You can change it where you like, however be cautious of the $fastcgi_skipcache stuff. Also make sure to update your fast cgi socket file location to where php-fpm places its socket.
# example FastCGI cache exception rules
set $fastcgi_skipcache 0;
if ($http_cookie ~ "users_login_cookie") {
set $fastcgi_skipcache 1;
}
if ($request_method = POST) {
set $fastcgi_skipcache 1;
}
if ($query_string != "") {
set $fastcgi_skipcache 1;
}
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
set $fastcgi_skipcache 1;
}
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
set $fastcgi_skipcache 1;
}
if ( $request_uri ~ "/wp/wp-login.php" ) {
set $fastcgi_skipcache 1;
}
if ( $request_uri ~ "/wp/wp-admin" ) {
set $fastcgi_skipcache 1;
}
# Global restrictions configuration file.
# Designed to be included in any server {} block.</p>
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~ /\. {
deny all;
}
location /admin {
return 301 /wp/wp-admin;
}
# Deny access to any files with a .php extension in the uploads directory
# Works in sub-directory installs and also in multisite network
# Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Accept-Encoding' 'gzip';
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|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;
}
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
add_header X-Cache $upstream_cache_status;
fastcgi_cache fastcgicache;
fastcgi_cache_bypass $fastcgi_skipcache;
fastcgi_no_cache $fastcgi_skipcache;
# This is a robust solution for path info security issue and works with "cgi.fix_pathinfo = 1" in /etc/php.ini (default)
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param APP_ENV prod;
fastcgi_read_timeout 600;
}
After creating your global wordpress cache configuration you will need to define your cache system in nginx by adding a file /etc/nginx/global/cache.conf and adding the following lines:
fastcgi_cache_path /var/cache/nginxfastcgi levels=1:2 keys_zone=fastcgicache:5m inactive=5m max_size=64m;
fastcgi_cache_key $scheme$request_method$host$request_uri;
# note: can also use HTTP headers to form the cache key, e.g.
fastcgi_cache_lock on;
fastcgi_cache_use_stale error timeout invalid_header updating http_500;
fastcgi_cache_valid 5m;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
And finally after that file is created you must include it in the nginx configuration by adding the following line to /etc/nginx/nginx.conf below client_max_body_size:
include /etc/nginx/global/cache.conf;
After that you must replace your fast cgi block with the following under any wordpress site configuration:
include global/wordpress_cache.conf;
jworkman/wordpress-fastcgi-cache 适用场景与选型建议
jworkman/wordpress-fastcgi-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 435 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「fastcgi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jworkman/wordpress-fastcgi-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jworkman/wordpress-fastcgi-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jworkman/wordpress-fastcgi-cache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Bust the Nginx FastCGI Cache when entries are saved or created.
An effective FastCGI to psr-7 adapter
Manage your OPcache & APCu cache through the CLI
A PHPFastCGI adapter for the Zend Expressive framework
Harmonize PHP module, CGI and FCGI/FastCGI environments by infering missing $_SERVER variables like REMOTE_USER and HTTP_AUTHORIZATION.
Simply serve fastcgi with reactphp
统计信息
- 总下载量: 435
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-01-09