minio + picgo 自建图床

minio + picgo 自建图床

Posted by BlueFat on Monday, November 27, 2023

obsidian安装插件实现贴入图片自动上传到图床

安装

mkdir -p /data/minio/{data,config}

docker 运行

docker run \
-p 9000:9000 \
-p 9090:9090 \
--name minio \
-d --restart=always \
-e "MINIO_ROOT_USER=admin" \
-e "MINIO_ROOT_PASSWORD=admin_password" \
-v /data/minio/data:/data \
-v /data/minio/config:/root/.minio \
minio/minio \
server /data --console-address ":9090"

docker-compose 运行

version: '3'
services:
  minio:
    image: minio/minio
    container_name: minio
    hostname: "minio"
    ports:
      - 9000:9000 # api 端口
      - 9090:9090 # console 端口
    environment:
      MINIO_ROOT_USER: admin   # 管理后台用户名, 最少3个字符
      MINIO_ROOT_PASSWORD: admin_password # 管理后台密码,最少8个字符
    volumes:
      - /data/minio/data:/data   # 映射数据目录
      - /data/minio/config:/root/.minio/ # 映射配置目录
    command: server /data --console-address ':9090' # 运行命令 指定容器中的目录和api端口 注意9090端口对应映射
    privileged: true
    restart: on-failure:3

Nginx 代理

Configure NGINX Proxy for MinIO Server

console web代理

upstream minio_console {
   server 127.0.0.1:9090;
}

server {
   listen       80;
   server_name  console.sundayhk.com;

   # Allow special characters in headers
   ignore_invalid_headers off;
   # Allow any size file to be uploaded.
   # Set to a value such as 1000m; to restrict file size to a specific value
   client_max_body_size 0;
   # Disable buffering
   proxy_buffering off;
   proxy_request_buffering off;

   location / {
      proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-NginX-Proxy true;

      # This is necessary to pass the correct IP to be hashed
      real_ip_header X-Real-IP;
      proxy_connect_timeout 300;

      # To support websocket
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      # chunked_transfer_encoding off; # 禁用此项,开启会导致一直在加载转圈
      proxy_pass http://minio_console/; 
   }
}

api代理

upstream minio_s3 {
   least_conn;
   server 127.0.0.1:9000;
}

server {
	listen       80;
	server_name oss.sundayhk.com;
	
	# Allow special characters in headers
	ignore_invalid_headers off;
	# Allow any size file to be uploaded.
	# Set to a value such as 1000m; to restrict file size to a specific value
	client_max_body_size 0;
	# Disable buffering
	proxy_buffering off;
	proxy_request_buffering off;
	
	location / {
		proxy_set_header Host $http_host;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_set_header X-NginX-Proxy true;
		
		# This is necessary to pass the correct IP to be hashed
		real_ip_header X-Real-IP;
		proxy_connect_timeout 300;
		
		# To support websocket
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		
		# chunked_transfer_encoding off; # 禁用此项,开启会导致一直在加载转圈
		proxy_pass http://minio_s3;
	}
	access_log /var/log/nginx/minio.log;
}

minio 操作

访问 http://console.sundayhk.com

创建Bucket

设置权限为public, 即外部可访问图片

此时上传图片 即可预览

通过api访问 (注意 需要将bucket设置为public 不然会提示没权限) http://oss.sundayhk.com/blog-pic/20231126233159.png

minio配置Service Account

下载配置 待会PicGo会用到

PicGo

https://github.com/Molunerfinn/PicGo/releases 搜索安装minio插件

填写minio api 域名或ip 及accessKey secreKey和bucket

这里注意选下

这里测试上传成功

osbidian 插件

安装 image auto upload plugin 即可 贴入 自动上传