update
Browse files
bak/2025-02-27 2250 实现代理访问访问,cline可用/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 目前已经实现静态的gemini代理,下面需要使用lua实现动态替换 备份时间为 2025-02-26 00:03
|
| 2 |
+
|
| 3 |
+
# 基于OpenResty基础镜像
|
| 4 |
+
FROM openresty/openresty:1.21.4.1-0-jammy
|
| 5 |
+
|
| 6 |
+
# 安装必要的包(可选)
|
| 7 |
+
RUN apt-get update && apt-get install -y \
|
| 8 |
+
curl \
|
| 9 |
+
vim \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
# 创建用户
|
| 13 |
+
RUN useradd -m -s /bin/bash myuser
|
| 14 |
+
|
| 15 |
+
# 创建目录
|
| 16 |
+
RUN mkdir -p /data/myapp
|
| 17 |
+
# RUN mkdir -p /usr/local/openresty/nginx/client_body_temp
|
| 18 |
+
RUN mkdir -p /usr/local/openresty/nginx
|
| 19 |
+
|
| 20 |
+
# 修改目录的所有者和权限
|
| 21 |
+
RUN chown -R myuser:myuser /data/myapp
|
| 22 |
+
RUN chmod -R 755 /data/myapp
|
| 23 |
+
RUN chown -R myuser:myuser /usr/local/openresty/nginx
|
| 24 |
+
RUN chmod -R 755 /usr/local/openresty/nginx
|
| 25 |
+
|
| 26 |
+
# 设置工作目录
|
| 27 |
+
WORKDIR /data/myapp
|
| 28 |
+
|
| 29 |
+
# 切换到新用户
|
| 30 |
+
USER myuser
|
| 31 |
+
|
| 32 |
+
# 复制Lua脚本和nginx配置文件到容器中
|
| 33 |
+
COPY app.lua /data/myapp/
|
| 34 |
+
# COPY app_v1.lua /data/myapp/
|
| 35 |
+
# COPY get_will_trim_path.lua /usr/local/openresty/nginx/
|
| 36 |
+
# COPY app /data/myapp/app
|
| 37 |
+
COPY nginx.conf /usr/local/openresty/nginx/conf/nginx.conf
|
| 38 |
+
|
| 39 |
+
# 指定容器启动时运行的命令
|
| 40 |
+
CMD ["openresty", "-g", "daemon off;"]
|
bak/2025-02-27 2250 实现代理访问访问,cline可用/nginx.conf
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 目前已经实现静态的gemini代理,下面需要使用lua实现动态替换 备份时间为 2025-02-26 00:03
|
| 2 |
+
worker_processes auto;
|
| 3 |
+
events {
|
| 4 |
+
worker_connections 1024;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
http {
|
| 8 |
+
include mime.types;
|
| 9 |
+
default_type application/octet-stream;
|
| 10 |
+
|
| 11 |
+
sendfile on;
|
| 12 |
+
keepalive_timeout 65;
|
| 13 |
+
|
| 14 |
+
lua_package_path '$prefix/lua/?.lua;$prefix/lualib/?.lua;;';
|
| 15 |
+
|
| 16 |
+
server {
|
| 17 |
+
listen 7860;
|
| 18 |
+
server_name localhost;
|
| 19 |
+
|
| 20 |
+
set $target_proto "";
|
| 21 |
+
set $target_host "";
|
| 22 |
+
set $target_path "";
|
| 23 |
+
|
| 24 |
+
# 主代理路径处理
|
| 25 |
+
location ~ ^/v1/(https?)/([^/]+)(/.*)$ {
|
| 26 |
+
resolver 8.8.8.8; # 指定一个公共 DNS 解析器
|
| 27 |
+
access_by_lua_block {
|
| 28 |
+
-- 设置目标变量
|
| 29 |
+
ngx.var.target_proto = ngx.var[1]
|
| 30 |
+
ngx.var.target_host = ngx.var[2]
|
| 31 |
+
ngx.var.target_path = ngx.var[3]
|
| 32 |
+
|
| 33 |
+
-- 处理特殊字符转义(如路径中的%2F)
|
| 34 |
+
ngx.var.target_path = ngx.re.gsub(ngx.var.target_path, "\\%2F", "/", "ijo")
|
| 35 |
+
}
|
| 36 |
+
proxy_pass $target_proto://$target_host$target_path;
|
| 37 |
+
proxy_set_header Host $target_host;
|
| 38 |
+
# 设置其他常用的请求头
|
| 39 |
+
proxy_set_header X-Real-IP $remote_addr;
|
| 40 |
+
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 41 |
+
proxy_set_header X-Forwarded-Proto $scheme;
|
| 42 |
+
}
|
| 43 |
+
}
|
| 44 |
+
}
|