baks-dev / files-cdn
文件资源CDN模块
v7.1.9
2024-09-17 20:57 UTC
Requires
- php: >=8.3
- baks-dev/core: ^7.1
Requires (Dev)
- roave/security-advisories: dev-latest
- symfony/test-pack: ^1.0
README
文件资源CDN模块
安装
建议在独立服务器和独立域名上安装!
$ composer require baks-dev/files-cdn
设置
添加目录并设置文件上传权限
$ sudo mkdir <path_to_project>/public/upload $ chown -R unit:unit <path_to_project>/public/upload
生成密码摘要
$ php bin/console security:hash-password
在配置文件 <path_to_cdn_project>/config/packages/security.php
中指定授权设置,并给出密码的哈希结果
<user>
- 用户<hash-password-result>
- 密码哈希结果
<?php namespace Symfony\Component\DependencyInjection\Loader\Configurator; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Config\SecurityConfig; return static function(SecurityConfig $config) { $config->enableAuthenticatorManager(true); $config->firewall('dev') ->pattern('^/(_(profiler|wdt)|css|images|js)/') ->security(false) ; $config->passwordHasher(PasswordAuthenticatedUserInterface::class)->algorithm('bcrypt'); $config->provider('in_memory_users') ->memory() ->user('<user>') ->password('<hash-password-result>') ->roles(['ROLE_CDN']) ; $config->firewall('main') ->pattern('^/cdn/upload') ->provider('in_memory_users') ->httpBasic() ; };
在主项目中,在环境文件 <path_to_cdn_project>/.env
中指定CDN主机和授权访问的密码
<user>
- 用户<you-plain-password>
- 密码的文本表示
###> CDN ### CDN_HOST=cdn.example.host CDN_USER=<user> CDN_PASS=<you-plain-password>
许可证 
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。