moderntribe/tribe-storage-statically-cdn
Composer 安装命令:
composer require moderntribe/tribe-storage-statically-cdn
包简介
Tribe Storage Plugin to add statically.io CDN support
README 文档
README
Provides dynamic image sizing and optimization via statically.io and only creates WordPress thumbnails for images that require hard cropping.
Installation Composer v1
Add the following to the composer.json repositories object:
"repositories": [ { "type": "vcs", "url": "git@github.com:moderntribe/tribe-storage-statically-cdn.git" } ]
Then run:
composer require moderntribe/tribe-storage-statically-cdn
Configuration
There are two ways to configure this plugin, either directly using the cdn.statically.io directly, or proxying
to that domain via Nginx.
Use statically.io URLs directly
Ensure you have defined the TRIBE_STORAGE_URL constant in wp-config.php to your cloud provider's publicly
accessible URL and it will be replaced to use Statically's CDN for images only:
NOTE: Image URLs are cached, ensure your flush your object cache if you make any changes to the following defines.
// Azure example define( 'TRIBE_STORAGE_URL', 'https://account.blob.core.windows.net/container' );
URL rewriting would look as follows:
- Original:
https://account.blob.core.windows.net/container/sites/4/2021/06/image.jpg - Rewritten:
https://cdn.statically.io/img/account.blob.core.windows.net/f=auto,w=1024,h=1024/container/sites/4/2021/06/image.jpg
Use statically.io as a proxy via Nginx
Ensure you do not have TRIBE_STORAGE_URL defined, and define the following in wp-config.php:
define( 'TRIBE_STORAGE_STATICALLY_PROXY', true );
Sample Nginx Proxy
Replace
account.blob.core.windows.netbelow with your cloud provider's hostname. Using the example from above it would be:account.blob.core.windows.net/container
# Root site and sub sites location ~* ^/(.+)?wp-content/uploads { try_files $uri $uri/ @statically; } # Check statically first location @statically { # adjust the /container below to your actual container name rewrite "^/(.+)?wp-content/uploads/(.*=.*?[\/])?(.+)$" /$2container/$3 break; proxy_http_version 1.1; resolver 1.1.1.1; proxy_set_header Connection ''; proxy_set_header Authorization ''; proxy_set_header Host cdn.statically.io; proxy_hide_header Set-Cookie; proxy_ignore_headers Set-Cookie; proxy_intercept_errors on; recursive_error_pages on; error_page 400 404 500 = @uploads; add_header X-Image-Path "$uri" always; proxy_pass https://cdn.statically.io/img/account.blob.core.windows.net$uri; } # Fallback to check Azure directly location @uploads { # remove any statically.io params, e.g f=auto,w=518,h=291/ rewrite ^/(.*=.*?[\/])?(.+)$ /$2 break; proxy_http_version 1.1; resolver 1.1.1.1; proxy_set_header Connection ''; proxy_set_header Authorization ''; proxy_set_header Host account.blob.core.windows.net; proxy_hide_header x-ms-blob-type; proxy_hide_header x-ms-lease-status; proxy_hide_header x-ms-request-id; proxy_hide_header x-ms-version; proxy_hide_header Set-Cookie; proxy_ignore_headers Set-Cookie; proxy_intercept_errors on; recursive_error_pages on; error_page 400 404 500 = @imageerror; add_header X-Image-Path "$uri" always; add_header Cache-Control max-age=31536000; proxy_pass https://account.blob.core.windows.net$uri; } # If both the above fail, show the default Nginx 404 error page location @imageerror { add_header X-Error-Uri "$uri" always; return 404; }
URL rewriting would look as follows, and proxied to Statically behind the scenes:
- Original:
https://example.com/wp-content/uploads/sites/4/2021/06/image.jpg - Rewritten:
https://example.com/wp-content/uploads/f=auto,w=1024,h=1024/sites/4/2021/06/image.jpg - Proxied URL:
https://cdn.statically.io/img/account.blob.core.windows.net/f=auto,w=1024,h=1024/container/sites/4/2021/06/image.jpg
Disable WordPress thumbnail creation
If you're not concerned with exact cropping, you can let statically.io resize your image based with keeping the same dimension ratio and disable thumbnail creation to see a large performance boost when uploading new images.
For this you have two options:
Option 1: Add this define to wp-config.php
define( 'TRIBE_STORAGE_STATICALLY_CREATE_THUMBNAILS', false );
Option 2: Make the tribe/storage/plugin/statically/create_thumbnails filter return false, e.g.
add_filter( 'tribe/storage/plugin/statically/create_thumbnails', '__return_false' );
NOTE: Don't forget to clear object caching and regenerate thumbnails each time this option is swapped.
Automated Testing
Testing provided via PHPUnit and the Brain Monkey testing suite.
Run Unit Tests
$ composer install $ ./vendor/bin/phpunit
More Resources:
moderntribe/tribe-storage-statically-cdn 适用场景与选型建议
moderntribe/tribe-storage-statically-cdn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 304 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 06 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「proxy」 「cdn」 「nginx」 「moderntribe」 「tribe-storage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moderntribe/tribe-storage-statically-cdn 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moderntribe/tribe-storage-statically-cdn 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moderntribe/tribe-storage-statically-cdn 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Lazy loading for middleware and request handlers
Automatically rewrites the URLs of media and assets to use a CDN
Quickly add bootstrap, jquery and more from CDNs
Get working public proxy list for free by PubProxy (No API key required).
Adds MD5 hashes to the URLs of your application's assets, so when they change, their URL changes.
Standalone proxy server in PHP sockets, I am using Guzzle to route the requests. Idea was if I can make HTTP Proxy Server in php to get more control over proxy and custom logic. Currently it only supports http requests you can choose port of your own choice plus if you want to make it public or priv
统计信息
- 总下载量: 304
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2021-06-24