File size: 2,678 Bytes
1b9fde9
d3fce70
1b9fde9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d8268b1
 
 
 
 
3530503
d8268b1
3530503
 
d8268b1
52f37c8
3530503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b9fde9
 
d8268b1
 
 
 
 
 
1b9fde9
0201840
1b9fde9
 
 
d8268b1
 
 
 
 
 
 
 
 
 
1b9fde9
 
 
 
 
 
 
 
 
3530503
1b9fde9
3530503
d8268b1
1b9fde9
 
d8268b1
 
 
 
3530503
d8268b1
1b9fde9
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
FROM ghcr.io/fish2018/pansou-web:latest
ENV ENABLED_PLUGINS="labi,zhizhen,shandian,duoduo,muou,wanou"
USER root

# 创建必要的目录并设置权限
RUN mkdir -p /var/cache/nginx/client_temp \
    /var/cache/nginx/proxy_temp \
    /var/cache/nginx/fastcgi_temp \
    /var/cache/nginx/uwsgi_temp \
    /var/cache/nginx/scgi_temp \
    /var/run \
    /var/log/nginx \
    /app/cache && \
    chmod -R 777 /var/cache/nginx \
    /var/run \
    /var/log/nginx \
    /app/cache

# 删除所有默认的 nginx 配置
RUN rm -f /etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/* /etc/nginx/sites-available/* 2>/dev/null || true

# 创建全新的 nginx 配置文件
RUN cat > /etc/nginx/conf.d/pansou.conf <<'EOF'
server {
    listen 7860 default_server;
    server_name _;
    
    # 前端静态文件
    root /app/frontend/dist;
    index index.html;
    
    # 前端路由
    location / {
        try_files $uri $uri/ /index.html;
    }
    
    # API 代理到后端
    location /api/ {
        proxy_pass http://127.0.0.1:8888;
        proxy_set_header Host $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_connect_timeout 30s;
        proxy_send_timeout 30s;
        proxy_read_timeout 30s;
    }
}
EOF

# 修改 nginx 主配置
RUN sed -i 's/^user\s/#user /g' /etc/nginx/nginx.conf && \
    sed -i 's|pid\s*/var/run/nginx.pid;|pid /tmp/nginx.pid;|g' /etc/nginx/nginx.conf

# 验证配置内容
RUN echo "=== Nginx config check ===" && \
    cat /etc/nginx/conf.d/pansou.conf && \
    echo "=== End of config ===" && \
    ls -la /etc/nginx/conf.d/

# 创建启动脚本
RUN cat > /start.sh <<'EOF'
#!/bin/sh
set -e

echo "=== Starting PanSou Service ==="

# 显示前端文件
echo "Checking frontend files..."
ls -la /app/frontend/dist/ | head -10

# 显示 nginx 配置
echo "Nginx configuration:"
cat /etc/nginx/conf.d/pansou.conf

echo "Starting PanSou backend service..."
# 启动后端 API 服务(后台运行)
cd /app && ./pansou &

# 等待后端服务启动
echo "Waiting for backend to start..."
sleep 3

# 检查后端是否启动
if ! curl -s http://localhost:8888/api/health > /dev/null 2>&1; then
    echo "Warning: Backend service may not be running properly"
else
    echo "Backend service started successfully on port 8888"
fi

# 测试 nginx 配置
echo "Testing nginx configuration..."
nginx -t

echo "Starting Nginx on port 7860..."
echo "Frontend root: /app/frontend/dist"
# 启动 nginx(前台运行)
exec nginx -g "daemon off;"
EOF

RUN chmod +x /start.sh

EXPOSE 7860
USER 1000
CMD ["/start.sh"]