minio server pool+domain模式实现静态website服务能力
基于server pool 的核心是提供一个灵活的扩容以及灾备能力,基于domain 约定方便进行数据路由,功能上类似aws s3 的
提供的website 托管能力
参考图
简单说明
- bucket 格式
bucket 格式类似了aws s3 托管模式 .<minio_domain> domain 就是我们实际请求的格式,MINIO_DOMAIN 配置核心是让minio 支持基于域名的访问模式 - 用户请求处理
对于用户的请求通过nginx 的server_name 路由到minio 集群中,当然一般website 同时也需要index 页面,基于nginx 精准匹配进行支持 - 边缘数据cache 可以直接基于nginx 的proxy_cache
- 对于外网的访问,用户只需要配置a 记录到lb 的ip 或者通过cname 解析也行
参考示例
为了测试方便,minio 部分使用了单节点模式,对于server pool 模式的可以参考我以前写的相关文章
- docker-compose 文件
version: '3.7'
services:
openresty:
image: openresty/openresty:1.21.4.1-alpine-fat
volumes:
- ./nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf
- ./nginx.log:/var/log/nginx.log
ports:
- "80:80"
minio1:
image: minio/minio:RELEASE.2022-03-26T06-49-28Z
volumes:
- data1-1:/data1
ports:
- "9001:9000"
- "19001:19001"
environment:
MINIO_ACCESS_KEY: minio
MINIO_SECRET_KEY: minio123
MINIO_DOMAIN: dalongrong.com # 此处配置了支持基于域名的模式访问
MINIO_HTTP_TRACE: /var/log/minio.log
command: server /data1 --console-address ":19001"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
interval: 30s
timeout: 20s
retries: 3
volumes:
data1-1:
- nginx 配置
worker_processes 1;
user root;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
log_format graylog2_json escape=json '{ "timestamp": "$time_local", '
'"remote_addr": "$remote_addr", '
'"body_bytes_sent": $body_bytes_sent, '
'"request_time": $request_time, '
'"response_status": $status, '
'"request": "$request", '
'"request_method": "$request_method", '
'"host": "$host",'
'"request_id": "$request_id",'
'"request_body":"$request_body",'
'"myhttp_host":"$myhttp_host",'
'"source_ip": "$http_x_forwarded_for",'
'"upstream_cache_status": "$upstream_cache_status",'
'"upstream_addr": "$upstream_addr",'
'"upstream_response_time": "$upstream_response_time",'
'"http_x_forwarded_for": "$http_x_forwarded_for",'
'"http_referrer": "$http_referer", '
'"http_user_agent": "$http_user_agent",'
'"realip":"$realip_remote_addr"}';
real_ip_header X-Forwarded-For;
resolver 127.0.0.11 ipv6=off;
real_ip_recursive on;
upstream imageproxy {
server minio1:9000;
}
server {
listen 80;
server_name ~^(.+)$;
charset utf-8;
default_type text/html;
location / {
default_type text/html;
index index.html index.htm;
proxy_set_header X-Forwarded-For $remote_addr;
access_log /var/log/nginx.log graylog2_json;
# 拼接Host 请求头,进行路由正确的请求处理(基于minio sub domain 模式)
set $myhttp_host $1.dalongrong.com;
proxy_set_header Host $myhttp_host;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_connect_timeout 80;
proxy_pass http://imageproxy;
}
# 精准匹配支持默认首页的配置,当前直接到index.html 可以基于规则进行配置(结合openresty)
location = /{
default_type text/html;
index index.html index.htm;
proxy_set_header X-Forwarded-For $remote_addr;
access_log /var/log/nginx.log graylog2_json;
set $myhttp_host $1.dalongrong.com;
proxy_set_header Host $myhttp_host;
client_body_buffer_size 10M;
client_max_body_size 10G;
proxy_buffers 1024 4k;
proxy_read_timeout 300;
proxy_connect_timeout 80;
proxy_pass http://imageproxy/index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
- 参考minio 数据
使用了域名格式的bucket
访问效果
本地测试需要需要配置hosts 文件
比如以上的需要配置
127.0.0.1 wwww.demoapp.com
127.0.0.1 rongfengliang.com
- 访问效果
说明
以上是一个简单的集成,通过sub domain 以及nginx 实现了类似aws s3 website 托管模式,好多东西可以改进调整,实现一些强大的功能
参考资料
https://min.io/docs/minio/linux/operations/concepts.html#minio-intro-server-pool
https://min.io/docs/minio/linux/operations/install-deploy-manage/expand-minio-deployment.html#expand-minio-distributed
https://www.cnblogs.com/rongfengliang/p/17262753.html
https://www.cnblogs.com/rongfengliang/p/17263939.html
https://docs.aws.amazon.com/AmazonS3/latest/userguide/VirtualHosting.html#VirtualHostingCustomURLs
https://nginx.org/en/docs/http/ngx_http_core_module.html#server_name
https://github.com/rongfengliang/hosting-static-website-with-minio-nginx
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2021-03-28 flatbuffers 代码集成
2021-03-28 flatbuffers 试用
2021-03-28 flatbuffers 谷歌开源的内存高效的序列化库
2020-03-28 bashible docker集成使用
2014-03-28 http-equiv 了解