Upload 3 files
Browse files- Dockerfile +31 -0
- nginx.conf +85 -0
- start.sh +5 -0
Dockerfile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
# FROM calciumion/new-api:latest as oneapi
|
| 3 |
+
FROM calciumion/new-api-horizon:latest as oneapi
|
| 4 |
+
|
| 5 |
+
FROM nginx:alpine
|
| 6 |
+
|
| 7 |
+
EXPOSE 7860
|
| 8 |
+
|
| 9 |
+
# 创建所有必要的目录并设置权限
|
| 10 |
+
RUN mkdir -p /data/logs && \
|
| 11 |
+
mkdir -p /logs && \
|
| 12 |
+
chmod -R 777 /data && \
|
| 13 |
+
chmod -R 777 /logs
|
| 14 |
+
|
| 15 |
+
# Nginx相关目录设置
|
| 16 |
+
RUN chmod 777 /var/cache/nginx && \
|
| 17 |
+
mkdir -p /var/log/nginx && \
|
| 18 |
+
chmod 777 /var/log/nginx && \
|
| 19 |
+
touch /var/run/nginx.pid && \
|
| 20 |
+
chmod 777 /var/run/nginx.pid
|
| 21 |
+
|
| 22 |
+
# 从oneapi镜像复制必要的文件
|
| 23 |
+
COPY --from=oneapi /one-api /one-api
|
| 24 |
+
COPY --from=oneapi /data /data
|
| 25 |
+
|
| 26 |
+
# 复制配置文件
|
| 27 |
+
COPY nginx.conf /etc/nginx/nginx.conf
|
| 28 |
+
COPY start.sh /start.sh
|
| 29 |
+
RUN chmod +x /start.sh
|
| 30 |
+
|
| 31 |
+
CMD ["/start.sh"]
|
nginx.conf
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
worker_processes auto;
|
| 3 |
+
|
| 4 |
+
# 设置最大打开文件数
|
| 5 |
+
worker_rlimit_nofile 65535;
|
| 6 |
+
|
| 7 |
+
events {
|
| 8 |
+
# 每个工作进程的最大连接数
|
| 9 |
+
worker_connections 65535;
|
| 10 |
+
|
| 11 |
+
# 启用多路复用
|
| 12 |
+
multi_accept on;
|
| 13 |
+
|
| 14 |
+
# 使用高效的事件处理模型
|
| 15 |
+
use epoll;
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
http {
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# 连接超时设置
|
| 22 |
+
keepalive_timeout 65;
|
| 23 |
+
keepalive_requests 100;
|
| 24 |
+
|
| 25 |
+
# 压缩设置
|
| 26 |
+
gzip on;
|
| 27 |
+
gzip_vary on;
|
| 28 |
+
gzip_proxied any;
|
| 29 |
+
gzip_comp_level 6;
|
| 30 |
+
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
|
| 31 |
+
|
| 32 |
+
# 日志配置
|
| 33 |
+
access_log /tmp/nginx_access.log;
|
| 34 |
+
error_log /tmp/nginx_error.log;
|
| 35 |
+
|
| 36 |
+
limit_req_zone $binary_remote_addr zone=one:10m rate=10r/s;
|
| 37 |
+
limit_conn_zone $binary_remote_addr zone=addr:10m;
|
| 38 |
+
# MIME类型
|
| 39 |
+
include /etc/nginx/mime.types;
|
| 40 |
+
|
| 41 |
+
# 性能优化的upstream配置
|
| 42 |
+
upstream backend {
|
| 43 |
+
least_conn; # 最少连接负载均衡
|
| 44 |
+
server 127.0.0.1:3000 max_fails=3 fail_timeout=30s;
|
| 45 |
+
keepalive 32; # 保持的后端连接数
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
server {
|
| 49 |
+
listen 7860 reuseport; # 启用端口重用
|
| 50 |
+
listen [::]:7860 reuseport;
|
| 51 |
+
server_name localhost;
|
| 52 |
+
|
| 53 |
+
location / {
|
| 54 |
+
limit_req zone=one burst=20 nodelay;
|
| 55 |
+
limit_conn addr 10;
|
| 56 |
+
proxy_pass http://backend;
|
| 57 |
+
proxy_set_header Upgrade $http_upgrade;
|
| 58 |
+
proxy_set_header Connection "upgrade";
|
| 59 |
+
proxy_set_header Host $host;
|
| 60 |
+
|
| 61 |
+
# 清除敏感头部
|
| 62 |
+
proxy_set_header X-Forwarded-For "";
|
| 63 |
+
proxy_set_header X-Real-IP "";
|
| 64 |
+
proxy_set_header X-Direct-Url "";
|
| 65 |
+
proxy_set_header X-Forwarded-Port "";
|
| 66 |
+
proxy_set_header X-Ip-Token "";
|
| 67 |
+
proxy_set_header X-Request-Id "";
|
| 68 |
+
proxy_set_header X-Amzn-Trace-Id "";
|
| 69 |
+
proxy_set_header X-Forwarded-Proto "";
|
| 70 |
+
|
| 71 |
+
# 代理优化
|
| 72 |
+
proxy_buffering off;
|
| 73 |
+
proxy_cache off;
|
| 74 |
+
proxy_connect_timeout 60s;
|
| 75 |
+
proxy_send_timeout 60s;
|
| 76 |
+
proxy_read_timeout 60s;
|
| 77 |
+
|
| 78 |
+
error_page 503 =429 /429.html;
|
| 79 |
+
}
|
| 80 |
+
# 429 错误页面
|
| 81 |
+
location = /429.html {
|
| 82 |
+
return 429 'Too Many Requests';
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
}
|
start.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
|
| 3 |
+
nginx &
|
| 4 |
+
/one-api
|
| 5 |
+
|