Chevereto 接入 minio 存储

Chevereto 版本:3.20.20

Chevereto 配置示例

MinIO 存储设置

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "*"
                ]
            },
            "Action": [
                "s3:GetBucketLocation"
            ],
            "Resource": [
                "arn:aws:s3:::chevereto"
            ]
        },
        {
            "Effect": "Allow",
            "Principal": {
                "AWS": [
                    "*"
                ]
            },
            "Action": [
                "s3:GetObject"
            ],
            "Resource": [
                "arn:aws:s3:::chevereto/*"
            ]
        }
    ]
}

将本地图片 URL 改为 S3 存储

参考:https://chevereto.com/community/threads/migrate-your-existing-images-to-s3.5388/

安装并使用 rclone 命令将本地文件传到 MinIO

rclone copy /home/wwwroot/website.com/images/ minio:/chevereto -P

文件传输完成后需要更新数据库,在外部存储页面检查 S3 存储 ID,并替换下面 <storage id>

UPDATE chv_images SET image_storage_id = <storage id> WHERE image_storage_id is null;

如果需要保持原有图片地址格式不变,可添加反向代理,示例是 Nginx

        location ^~ /images/ {
            proxy_set_header Host 'chevereto.minio.domain.com';
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass https://chevereto.minio.domain.com/;
        }

编辑存储,修改 URL 选项为 https://website.com/images/ 测试访问即可。


注意事项

  1. 需要修改存储桶 Access Policy
  2. URL 选项可以自己在 Minio 服务器那边再反代一次,不影响上传

以下内容不再需要设置


需要修改 Chevereto 源码,共 2 个位置:

app/app/lib/classes/class.storage.php
app/lib/classes/class.storage.php

在文件内搜索 S3Client::factory 在参数内加入以下设置即可:

'use_path_style_endpoint' => true,
'signatureVersion' => 'v2'

示例(加粗位置)

case 's3compatible':
    $factoria = [
        'version' => '2006-03-01',
        'region' => $storage['region'],
        'command.params' => ['PathStyle' => true],
        'credentials' => [
            'key' => $storage['key'],
            'secret' => $storage['secret'],
        ],
        'http' => [
            'verify' => CaBundle::getBundledCaBundlePath(),
        ],
        'use_path_style_endpoint' => true,
        'signatureVersion' => 'v2'
    ];
    if ($api_type == 's3compatible') {
        $factoria['endpoint'] = $storage['server'];
    }

    return \Aws\S3\S3Client::factory($factoria);

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据