Skip to content

Commit 1ffc017

Browse files
committed
feat: add alist proxy server
1 parent 6f82b53 commit 1ffc017

12 files changed

+276
-18
lines changed

Diff for: docker/.env.example

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ NACOS_PASS=nacos
66

77
MINIO_PORT_API=9000
88
MINIO_PORT_CONSOLE=9001
9+
MINIO_PORT_PROXY=9010
910
# Notes:
1011
# - MinIO password should be more than 8 characters
1112
# - Root password is password to login console
1213
# - Non-root password is for foreign API access
1314
MINIO_ROOT_USER=admin
1415
MINIO_ROOT_PASS=pw12345678
15-
MINIO_USER=minio
16-
MINIO_PASS=MINIO_123456
1716
MINIO_BUCKET_IMAGE=images
1817
# Note: Access key length should be between 3 and 20
1918
MINIO_KEY=KYJG_UPLOAD_KEY
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM nginx:1.25-alpine
2+
3+
WORKDIR /data
4+
ADD docker/config/img-alist-builder/minio-proxy /etc/nginx
5+
6+
RUN mkdir -p ./log && \
7+
mkdir -p ./cache/proxy_temp_dir && \
8+
mkdir -p ./cache/proxy_cache_dir && \
9+
chown -R nginx:nginx .
10+
11+
VOLUME ["/data/cache", "/data/log"]
12+
EXPOSE 80

Diff for: docker/composer/docker-compose.img-alist-build.yml

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ services:
55
build:
66
context: ${PROJECT_BASE}
77
dockerfile: docker/composer/docker-compose.img-alist-build.minio.Dockerfile
8+
minio-proxy:
9+
image: gsapi/minio-proxy
10+
build:
11+
context: ${PROJECT_BASE}
12+
dockerfile: docker/composer/docker-compose.img-alist-build.minio-proxy.Dockerfile
813
minio-img2webp:
914
image: gsapi/minio-img2webp
1015
build:

Diff for: docker/composer/docker-compose.img-alist-run.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ services:
3535
environment:
3636
MINIO_ROOT_USER: ${MINIO_ROOT_USER}
3737
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASS}
38+
MINIO_BROWSER_REDIRECT_URL: http://localhost:${MINIO_PORT_CONSOLE:-9001}
3839
volumes:
3940
- ${DATA_DIR}/minio/config:/root/.minio
4041
- ${DATA_DIR}/minio/data:/data
@@ -61,8 +62,7 @@ services:
6162
aliases:
6263
- minio-proxy.local
6364
volumes:
64-
- ${DATA_DIR}/minio-proxy/pid:/var/run
65-
- ${DATA_DIR}/minio-proxy/cache:/var/cache/nginx
65+
- ${DATA_DIR}/minio-proxy/cache:/data/cache
6666
- ${DATA_DIR}/minio-proxy/log:/data/log
6767
ports:
6868
- ${MINIO_PORT_PROXY:-9010}:80
@@ -131,8 +131,6 @@ services:
131131
environment:
132132
MINIO_ROOT_USERNAME: ${MINIO_ROOT_USER}
133133
MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASS}
134-
MINIO_USERNAME: ${MINIO_USER}
135-
MINIO_PASSWORD: ${MINIO_PASS}
136134
MINIO_BUCKET_IMAGE: ${MINIO_BUCKET_IMAGE}
137135
MINIO_KEY: ${MINIO_KEY}
138136
MINIO_SECRET: ${MINIO_SECRET}
@@ -153,6 +151,7 @@ services:
153151
ALIST_USERNAME: ${ALIST_USERNAME}
154152
ALIST_PASSWORD: ${ALIST_PASSWORD}
155153
ALIST_MOUNT_PATH: ${ALIST_MOUNT_PATH}
154+
ALIST_CACHE_EXPIRE: ${ALIST_CACHE_EXPIRE}
156155
MINIO_BUCKET_IMAGE: ${MINIO_BUCKET_IMAGE}
157156
MINIO_KEY: ${MINIO_KEY}
158157
MINIO_SECRET: ${MINIO_SECRET}

Diff for: docker/config/apt/debian-buster.list

-3
This file was deleted.

Diff for: docker/config/img-alist-builder/alist-init/init-test.ps1

Whitespace-only changes.

Diff for: docker/config/img-alist-builder/alist-init/init.ps1

+22-5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ function Encrypt-Password {
110110
}
111111
}
112112

113+
function ConvertTo-Integer {
114+
param(
115+
[Parameter(
116+
Mandatory = $true,
117+
ValueFromPipeline = $true,
118+
ValueFromPipelineByPropertyName = $true
119+
)]
120+
[Object] $NumericString
121+
)
122+
123+
process {
124+
$numberStr = "{0}" -f $NumericString;
125+
$number = [int] $numberStr;
126+
return $number;
127+
}
128+
}
129+
113130
# Process steps
114131
function Step-Login {
115132
$loginRes = Fetch-Api Post "api/auth/login/hash" -Body @{
@@ -136,9 +153,9 @@ function Step-AddStorage {
136153
mount_path = ${Env:ALIST_MOUNT_PATH}
137154
order = 0
138155
remark = "Image MinIO Storage"
139-
cache_expiration = ${Env:ALIST_CACHE_EXPIRE}
156+
cache_expiration = ConvertTo-Integer ${Env:ALIST_CACHE_EXPIRE}
140157
web_proxy = $false
141-
webdav_policy = "native_proxy"
158+
webdav_policy = "302_redirect"
142159
down_proxy_url = ""
143160
extract_folder = ""
144161
enable_sign = $false
@@ -148,12 +165,12 @@ function Step-AddStorage {
148165
addition = ConvertTo-Json @{
149166
root_folder_path = "/"
150167
bucket = ${Env:MINIO_BUCKET_IMAGE}
151-
endpoint = "http://minio.local:9000"
152-
region = "alist"
168+
endpoint = "http://minio-proxy.local:80"
169+
region = "minio"
153170
access_key_id = ${Env:MINIO_KEY}
154171
secret_access_key = ${Env:MINIO_SECRET}
155172
session_token = ""
156-
custom_host = "minio.local:9000"
173+
custom_host = "minio-proxy.local:80"
157174
sign_url_expire = 4
158175
placeholder = ""
159176
force_path_style = $true

Diff for: docker/config/img-alist-builder/minio-init/init.sh

+7-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ LOCK_FILE=${DATA_DIR}/initialized.lock
77
# Initialization steps
88
function step_init_minio () {
99
mc alias set minio http://minio.local:9000 "${MINIO_ROOT_USERNAME}" "${MINIO_ROOT_PASSWORD}"
10-
mc admin user add minio "${MINIO_USERNAME}" "${MINIO_PASSWORD}"
11-
mc admin policy attach minio consoleAdmin --user "${MINIO_USERNAME}"
1210
mc admin user svcacct add \
1311
--access-key "${MINIO_KEY}" \
1412
--secret-key "${MINIO_SECRET}" \
15-
minio "${MINIO_USERNAME}"
13+
minio "${MINIO_ROOT_USERNAME}"
1614
}
1715

1816
function step_add_img2webp_trigger () {
@@ -25,7 +23,12 @@ function step_add_img2webp_trigger () {
2523
queue_dir="" \
2624
queue_limit="0"
2725
mc admin service restart minio
28-
mc mb minio/${MINIO_BUCKET_IMAGE}
26+
mc mb \
27+
--ignore-existing \
28+
--region "minio" \
29+
--with-versioning \
30+
minio/${MINIO_BUCKET_IMAGE}
31+
mc anonymous set public minio/${MINIO_BUCKET_IMAGE}
2932
mc event add minio/${MINIO_BUCKET_IMAGE} arn:minio:sqs::1:redis --suffix .jpg --event put
3033
mc event add minio/${MINIO_BUCKET_IMAGE} arn:minio:sqs::1:redis --suffix .jpeg --event put
3134
mc event add minio/${MINIO_BUCKET_IMAGE} arn:minio:sqs::1:redis --suffix .jfif --event put
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
user nginx;
2+
worker_processes auto;
3+
error_log /data/log/nginx-error.log crit;
4+
pid /var/run/nginx.pid;
5+
6+
include /etc/nginx/modules-enabled/*.conf;
7+
8+
worker_rlimit_nofile 51200;
9+
10+
stream
11+
{
12+
log_format tcp_format
13+
'$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|'
14+
'$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|'
15+
'$upstream_connect_time';
16+
17+
access_log /data/log/tcp-access.log tcp_format;
18+
error_log /data/log/tcp-error.log;
19+
include /etc/nginx/tcp/*.conf;
20+
}
21+
22+
events
23+
{
24+
use epoll;
25+
worker_connections 51200;
26+
multi_accept on;
27+
}
28+
29+
http
30+
{
31+
log_format http_format
32+
'{'
33+
' "host": "$host",'
34+
' "request": "$request"'
35+
'}';
36+
37+
map $http_upgrade $connection_upgrade
38+
{
39+
default upgrade;
40+
'' close;
41+
}
42+
43+
include mime.types;
44+
include proxy.conf;
45+
46+
default_type application/octet-stream;
47+
48+
server_names_hash_bucket_size 512;
49+
client_header_buffer_size 32k;
50+
large_client_header_buffers 4 32k;
51+
client_max_body_size 300m;
52+
53+
sendfile on;
54+
tcp_nopush on;
55+
56+
keepalive_timeout 60;
57+
58+
tcp_nodelay on;
59+
60+
fastcgi_connect_timeout 300;
61+
fastcgi_send_timeout 300;
62+
fastcgi_read_timeout 300;
63+
fastcgi_buffer_size 64k;
64+
fastcgi_buffers 4 64k;
65+
fastcgi_busy_buffers_size 128k;
66+
fastcgi_temp_file_write_size 256k;
67+
fastcgi_intercept_errors on;
68+
69+
gzip on;
70+
gzip_min_length 1k;
71+
gzip_buffers 4 16k;
72+
gzip_http_version 1.1;
73+
gzip_comp_level 2;
74+
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
75+
gzip_vary on;
76+
gzip_proxied expired no-cache no-store private auth;
77+
gzip_disable "MSIE [1-6]\.";
78+
79+
limit_conn_zone $binary_remote_addr zone=perip:10m;
80+
limit_conn_zone $server_name zone=perserver:10m;
81+
82+
server_tokens off;
83+
access_log /data/log/http-access.log http_format;
84+
error_log /data/log/http-error.log;
85+
86+
include /etc/nginx/vhost/*.conf;
87+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
proxy_temp_path /data/cache/proxy_temp_dir;
2+
proxy_cache_path /data/cache/proxy_cache_dir levels=1:2 keys_zone=cache_one:20m inactive=1d max_size=5g;
3+
client_body_buffer_size 512k;
4+
proxy_connect_timeout 60;
5+
proxy_read_timeout 60;
6+
proxy_send_timeout 60;
7+
proxy_buffer_size 32k;
8+
proxy_buffers 4 64k;
9+
proxy_busy_buffers_size 128k;
10+
proxy_temp_file_write_size 128k;
11+
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
12+
proxy_cache cache_one;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
location /
2+
{
3+
proxy_pass http://minio.local:9000/;
4+
proxy_set_header Host $http_host;
5+
proxy_set_header X-Real-IP $remote_addr;
6+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
7+
proxy_set_header REMOTE-HOST $remote_addr;
8+
proxy_set_header Upgrade $http_upgrade;
9+
proxy_set_header Connection $connection_upgrade;
10+
proxy_http_version 1.1;
11+
12+
add_header X-Cache $upstream_cache_status;
13+
14+
set $static_file_MINIO_IMG 0;
15+
if ( $uri ~* "\.(gif|png|jpg|jpeg|jfif|webp|css|js|woff|woff2|ttf|eot)$" )
16+
{
17+
set $static_file_MINIO_IMG 1;
18+
expires 1m;
19+
}
20+
if ( $static_file_MINIO_IMG = 0 )
21+
{
22+
add_header Cache-Control no-cache;
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
server
2+
{
3+
listen 80;
4+
index index.php index.html index.htm default.php default.htm default.html;
5+
root /data;
6+
7+
add_header Strict-Transport-Security "max-age=31536000";
8+
error_page 497 http://$host$request_uri;
9+
add_header Access-Control-Allow-Origin '*' always;
10+
11+
# 引用反向代理规则
12+
include proxy/minio-proxy.conf;
13+
14+
# 禁止访问的文件或目录
15+
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
16+
{
17+
return 404;
18+
}
19+
20+
# 一键申请SSL证书验证目录相关设置
21+
location ~ \.well-known
22+
{
23+
allow all;
24+
}
25+
26+
# 禁止在证书验证目录放入敏感文件
27+
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" )
28+
{
29+
return 403;
30+
}
31+
32+
set $uri2 $uri;
33+
location ~ .*\.(webp)$
34+
{
35+
proxy_pass http://minio.local:9000;
36+
proxy_set_header X-Real-IP $remote_addr;
37+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
38+
proxy_set_header X-Forwarded-Proto $scheme;
39+
proxy_set_header Host $http_host;
40+
41+
proxy_connect_timeout 300;
42+
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
43+
proxy_http_version 1.1;
44+
proxy_set_header Connection "";
45+
proxy_intercept_errors on;
46+
error_page 404 = @other;
47+
}
48+
49+
location @other
50+
{
51+
rewrite ^(.*) $uri2 break;
52+
proxy_pass http://minio.local:9000;
53+
proxy_set_header X-Real-IP $remote_addr;
54+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
55+
proxy_set_header X-Forwarded-Proto $scheme;
56+
proxy_set_header Host $http_host;
57+
58+
proxy_connect_timeout 300;
59+
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
60+
proxy_http_version 1.1;
61+
proxy_set_header Connection "";
62+
}
63+
64+
location ~ .*\.(jpg|jpeg|png|jfif)$
65+
{
66+
expires 1d;
67+
set $flag 0;
68+
if ( $http_accept ~* '(image/webp)' )
69+
{
70+
# 判断来源设备是否支持 WebP
71+
set $flag "${flag}1";
72+
}
73+
if ( $request_method ~* 'GET' )
74+
{
75+
#判断来源是否是 GET
76+
set $flag "${flag}2";
77+
}
78+
if ( $flag = "012" ) {
79+
rewrite ^/(.*)\.\w+$ /$1.webp last;
80+
}
81+
82+
proxy_pass http://minio.local:9000;
83+
proxy_set_header X-Real-IP $remote_addr;
84+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
85+
proxy_set_header X-Forwarded-Proto $scheme;
86+
proxy_set_header Host $http_host;
87+
88+
proxy_connect_timeout 300;
89+
# Default is HTTP/1, keepalive is only enabled in HTTP/1.1
90+
proxy_http_version 1.1;
91+
proxy_set_header Connection "";
92+
}
93+
94+
location ~ .*\.(js|css)?$
95+
{
96+
expires 12h;
97+
error_log /dev/null;
98+
access_log /dev/null;
99+
}
100+
101+
access_log /dev/null;
102+
error_log /data/log/minio-proxy.local-error.log;
103+
}

0 commit comments

Comments
 (0)