File size: 917 Bytes
610f39c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/bin/bash

# 设置默认值
FRONTEND_PORT=${FRONTEND_PORT:-80}
BACKEND_PORT=${BACKEND_PORT:-7860}
BACKEND_HOST=${BACKEND_HOST:-0.0.0.0}
WORKERS=${WORKERS:-4}
THREADS=${THREADS:-2}
TIMEOUT=${TIMEOUT:-120}

# 在Linux环境下添加host.docker.internal解析
# if ! grep -q "host.docker.internal" /etc/hosts; then
#     DOCKER_INTERNAL_HOST="$(ip route | grep default | awk '{print $3}')"
#     echo "$DOCKER_INTERNAL_HOST host.docker.internal" >> /etc/hosts
# fi

# 替换nginx配置中的端口
sed -i "s/listen 80/listen $FRONTEND_PORT/g" /etc/nginx/conf.d/default.conf
sed -i "s/host.docker.internal:7860/localhost:$BACKEND_PORT/g" /etc/nginx/conf.d/default.conf

# 启动nginx
nginx

# 启动gunicorn
gunicorn --bind $BACKEND_HOST:$BACKEND_PORT \
    --workers $WORKERS \
    --threads $THREADS \
    --worker-class gthread \
    --timeout $TIMEOUT \
    --access-logfile - \
    --error-logfile - \
    app:app