Update Dockerfile
Browse files- Dockerfile +35 -5
Dockerfile
CHANGED
|
@@ -16,9 +16,37 @@ RUN mkdir -p /var/cache/nginx/client_temp \
|
|
| 16 |
/var/log/nginx \
|
| 17 |
/app/cache
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
RUN
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
sed -i 's|pid\s*/var/run/nginx.pid;|pid /tmp/nginx.pid;|g' /etc/nginx/nginx.conf
|
| 23 |
|
| 24 |
# 创建启动脚本
|
|
@@ -35,11 +63,13 @@ echo "Waiting for backend to start..."
|
|
| 35 |
sleep 3
|
| 36 |
|
| 37 |
# 检查后端是否启动
|
| 38 |
-
if ! curl -s http://localhost:8888/api/health > /dev/null; then
|
| 39 |
echo "Warning: Backend service may not be running properly"
|
|
|
|
|
|
|
| 40 |
fi
|
| 41 |
|
| 42 |
-
echo "Starting Nginx..."
|
| 43 |
# 启动 nginx(前台运行)
|
| 44 |
exec nginx -g "daemon off;"
|
| 45 |
EOF
|
|
|
|
| 16 |
/var/log/nginx \
|
| 17 |
/app/cache
|
| 18 |
|
| 19 |
+
# 创建 nginx 配置文件
|
| 20 |
+
RUN cat > /etc/nginx/conf.d/default.conf <<'EOF'
|
| 21 |
+
server {
|
| 22 |
+
listen 7860;
|
| 23 |
+
server_name _;
|
| 24 |
+
|
| 25 |
+
# 前端静态文件
|
| 26 |
+
root /usr/share/nginx/html;
|
| 27 |
+
index index.html;
|
| 28 |
+
|
| 29 |
+
# 前端路由
|
| 30 |
+
location / {
|
| 31 |
+
try_files $uri $uri/ /index.html;
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
# API 代理到后端
|
| 35 |
+
location /api/ {
|
| 36 |
+
proxy_pass http://127.0.0.1:8888;
|
| 37 |
+
proxy_set_header Host $host;
|
| 38 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 39 |
+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 40 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 41 |
+
proxy_connect_timeout 30s;
|
| 42 |
+
proxy_send_timeout 30s;
|
| 43 |
+
proxy_read_timeout 30s;
|
| 44 |
+
}
|
| 45 |
+
}
|
| 46 |
+
EOF
|
| 47 |
+
|
| 48 |
+
# 修改 nginx 主配置
|
| 49 |
+
RUN sed -i 's/^user\s/#user /g' /etc/nginx/nginx.conf && \
|
| 50 |
sed -i 's|pid\s*/var/run/nginx.pid;|pid /tmp/nginx.pid;|g' /etc/nginx/nginx.conf
|
| 51 |
|
| 52 |
# 创建启动脚本
|
|
|
|
| 63 |
sleep 3
|
| 64 |
|
| 65 |
# 检查后端是否启动
|
| 66 |
+
if ! curl -s http://localhost:8888/api/health > /dev/null 2>&1; then
|
| 67 |
echo "Warning: Backend service may not be running properly"
|
| 68 |
+
else
|
| 69 |
+
echo "Backend service started successfully"
|
| 70 |
fi
|
| 71 |
|
| 72 |
+
echo "Starting Nginx on port 7860..."
|
| 73 |
# 启动 nginx(前台运行)
|
| 74 |
exec nginx -g "daemon off;"
|
| 75 |
EOF
|