File size: 1,430 Bytes
0e4daa3
 
 
 
 
 
d145753
 
0e4daa3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
968af2e
 
 
 
 
0e4daa3
968af2e
 
 
 
d145753
968af2e
 
 
0e4daa3
d145753
0e4daa3
 
 
 
 
 
 
 
1293447
0e4daa3
 
 
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
# 使用官方镜像
FROM calciumion/new-api:latest

# 设置时区(必须)
ENV TZ=Asia/Shanghai

# 使用 Alpine 包管理器安装 nginx
RUN apk add --no-cache nginx

# 创建 nginx 配置
RUN echo 'events { worker_connections 1024; } \
        http { \
            server { \
                listen 7860; \
                location / { \
                    proxy_pass http://127.0.0.1:3000; \
                    proxy_set_header Host $host; \
                    proxy_set_header X-Real-IP $remote_addr; \
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; \
                } \
            } \
        }' > /etc/nginx/nginx.conf

# 创建数据目录并设置权限(关键修复)
RUN mkdir -p /data && \
    chmod 777 /data && \
    mkdir -p /data/logs && \
    chmod 777 /data/logs

# 创建 .env 文件(消除警告)
RUN echo "# Hugging Face Spaces Environment Variables" > /.env

# 创建启动脚本(修复权限问题)
RUN echo '#!/bin/sh \
        # 确保数据目录权限(挂载后可能被重置) \
        chmod 777 /data \
        chmod 777 /data/logs \
        # 启动 nginx(后台运行) \
        nginx & \
        # 启动 NewAPI(前台运行) \
        exec /app/docker-entrypoint.sh' > /start.sh && \
    chmod +x /start.sh

# 暴露端口
EXPOSE 7860

# 设置数据卷(Spaces 会自动挂载)
# VOLUME /data

# 启动命令
CMD ["/start.sh"]