huanbao commited on
Commit
5c0c7d7
·
verified ·
1 Parent(s): 77d5f59

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +102 -2
Dockerfile CHANGED
@@ -1,4 +1,104 @@
1
- FROM ghcr.io/fish2018/pansou-web
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  EXPOSE 7860
4
- EXPOSE 8888
 
 
1
+ FROM ghcr.io/fish2018/pansou-web:latest
2
+ USER root
3
+
4
+ # 创建必要的目录并设置权限
5
+ RUN mkdir -p /var/cache/nginx/client_temp \
6
+ /var/cache/nginx/proxy_temp \
7
+ /var/cache/nginx/fastcgi_temp \
8
+ /var/cache/nginx/uwsgi_temp \
9
+ /var/cache/nginx/scgi_temp \
10
+ /var/run \
11
+ /var/log/nginx \
12
+ /app/cache && \
13
+ chmod -R 777 /var/cache/nginx \
14
+ /var/run \
15
+ /var/log/nginx \
16
+ /app/cache
17
+
18
+ # 删除所有默认的 nginx 配置
19
+ RUN rm -f /etc/nginx/conf.d/*.conf /etc/nginx/sites-enabled/* /etc/nginx/sites-available/* 2>/dev/null || true
20
+
21
+ # 创建全新的 nginx 配置文件
22
+ RUN cat > /etc/nginx/conf.d/pansou.conf <<'EOF'
23
+ server {
24
+ listen 7860 default_server;
25
+ server_name _;
26
+
27
+ # 前端静态文件
28
+ root /app/frontend/dist;
29
+ index index.html;
30
+
31
+ # 前端路由
32
+ location / {
33
+ try_files $uri $uri/ /index.html;
34
+ }
35
+
36
+ # API 代理到后端
37
+ location /api/ {
38
+ proxy_pass http://127.0.0.1:8888;
39
+ proxy_set_header Host $host;
40
+ proxy_set_header X-Real-IP $remote_addr;
41
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
42
+ proxy_set_header X-Forwarded-Proto $scheme;
43
+ proxy_connect_timeout 30s;
44
+ proxy_send_timeout 30s;
45
+ proxy_read_timeout 30s;
46
+ }
47
+ }
48
+ EOF
49
+
50
+ # 修改 nginx 主配置
51
+ RUN sed -i 's/^user\s/#user /g' /etc/nginx/nginx.conf && \
52
+ sed -i 's|pid\s*/var/run/nginx.pid;|pid /tmp/nginx.pid;|g' /etc/nginx/nginx.conf
53
+
54
+ # 验证配置内容
55
+ RUN echo "=== Nginx config check ===" && \
56
+ cat /etc/nginx/conf.d/pansou.conf && \
57
+ echo "=== End of config ===" && \
58
+ ls -la /etc/nginx/conf.d/
59
+
60
+ # 创建启动脚本
61
+ RUN cat > /start.sh <<'EOF'
62
+ #!/bin/sh
63
+ set -e
64
+
65
+ echo "=== Starting PanSou Service ==="
66
+
67
+ # 显示前端文件
68
+ echo "Checking frontend files..."
69
+ ls -la /app/frontend/dist/ | head -10
70
+
71
+ # 显示 nginx 配置
72
+ echo "Nginx configuration:"
73
+ cat /etc/nginx/conf.d/pansou.conf
74
+
75
+ echo "Starting PanSou backend service..."
76
+ # 启动后端 API 服务(后台运行)
77
+ cd /app && ./pansou &
78
+
79
+ # 等待后端服务启动
80
+ echo "Waiting for backend to start..."
81
+ sleep 3
82
+
83
+ # 检查后端是否启动
84
+ if ! curl -s http://localhost:8888/api/health > /dev/null 2>&1; then
85
+ echo "Warning: Backend service may not be running properly"
86
+ else
87
+ echo "Backend service started successfully on port 8888"
88
+ fi
89
+
90
+ # 测试 nginx 配置
91
+ echo "Testing nginx configuration..."
92
+ nginx -t
93
+
94
+ echo "Starting Nginx on port 7860..."
95
+ echo "Frontend root: /app/frontend/dist"
96
+ # 启动 nginx(前台运行)
97
+ exec nginx -g "daemon off;"
98
+ EOF
99
+
100
+ RUN chmod +x /start.sh
101
 
102
  EXPOSE 7860
103
+ USER 1000
104
+ CMD ["/start.sh"]