update
Browse files- Dockerfile copy +0 -31
- get_ups.lua +0 -1
- nginx copy.conf +0 -101
- script.lua +0 -1
- somefile.txt +0 -1
Dockerfile copy
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
# 基于基础镜像(例如 Ubuntu)
|
| 2 |
-
FROM openresty/openresty:1.21.4.1-0-jammy
|
| 3 |
-
|
| 4 |
-
# 安装必要的包(可选)
|
| 5 |
-
RUN apt-get update && apt-get install -y \
|
| 6 |
-
curl \
|
| 7 |
-
vim \
|
| 8 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 9 |
-
|
| 10 |
-
# 创建用户
|
| 11 |
-
RUN useradd -m -s /bin/bash myuser
|
| 12 |
-
|
| 13 |
-
# 创建目录
|
| 14 |
-
RUN mkdir -p /data/myapp
|
| 15 |
-
|
| 16 |
-
# 修改目录的所有者和权限
|
| 17 |
-
RUN chown -R myuser:myuser /data/myapp
|
| 18 |
-
RUN chmod -R 755 /data/myapp
|
| 19 |
-
|
| 20 |
-
# 设置工作目录
|
| 21 |
-
WORKDIR /data/myapp
|
| 22 |
-
|
| 23 |
-
# 切换到新用户(可选)
|
| 24 |
-
USER myuser
|
| 25 |
-
|
| 26 |
-
# 其他操作...
|
| 27 |
-
# 例如:复制文件到容器中
|
| 28 |
-
COPY somefile.txt /data/myapp/
|
| 29 |
-
|
| 30 |
-
# 指定容器启动时运行的命令
|
| 31 |
-
CMD ["echo", "Hello from myuser!"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_ups.lua
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
return "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions"
|
|
|
|
|
|
nginx copy.conf
DELETED
|
@@ -1,101 +0,0 @@
|
|
| 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 |
-
# 主代理路径处理
|
| 21 |
-
location ~ ^/v1/(https?)/([^/]+)(/.*)$ {
|
| 22 |
-
access_by_lua_block {
|
| 23 |
-
ngx.var.target_proto = ngx.var[1]
|
| 24 |
-
ngx.var.target_host = ngx.var[2]
|
| 25 |
-
ngx.var.target_path = ngx.var[3]
|
| 26 |
-
--ngx.say(ngx.var[1])
|
| 27 |
-
--ngx.say(ngx.var[2])
|
| 28 |
-
--ngx.say(ngx.var[3])
|
| 29 |
-
|
| 30 |
-
-- 处理特殊字符转义(如路径中的%2F)
|
| 31 |
-
ngx.var.target_path = ngx.re.gsub(ngx.var.target_path, "\\%2F", "/", "ijo")
|
| 32 |
-
}
|
| 33 |
-
|
| 34 |
-
proxy_pass $target_proto://$target_host$target_path;
|
| 35 |
-
proxy_set_header Host $target_host;
|
| 36 |
-
|
| 37 |
-
# HTTPS目标需要配置SSL参数
|
| 38 |
-
proxy_ssl_server_name on;
|
| 39 |
-
proxy_ssl_name $target_host;
|
| 40 |
-
proxy_ssl_protocols TLSv1.2 TLSv1.3;
|
| 41 |
-
|
| 42 |
-
# 调试用(生产环境应开启验证)
|
| 43 |
-
proxy_ssl_verify off;
|
| 44 |
-
|
| 45 |
-
# 保持原始请求头
|
| 46 |
-
proxy_set_header X-Original-Host $http_host;
|
| 47 |
-
proxy_set_header X-Forwarded-Proto $scheme;
|
| 48 |
-
|
| 49 |
-
# 超时设置
|
| 50 |
-
proxy_connect_timeout 5s;
|
| 51 |
-
proxy_read_timeout 30s;
|
| 52 |
-
}
|
| 53 |
-
|
| 54 |
-
# location / {
|
| 55 |
-
# default_type text/html;
|
| 56 |
-
|
| 57 |
-
# set $old_path "/v1/https/generativelanguage.googleapis.com";
|
| 58 |
-
# echo "old_path: " $old_path;
|
| 59 |
-
# # rewrite ^$old_path/(.*)$ /$1 break; # 裁剪路径
|
| 60 |
-
# # rewrite ^${old_path}/(.*)$ /$1 break; # 裁剪路径
|
| 61 |
-
# # rewrite ^/v1/https/generativelanguage.googleapis.com/(.*)$ /$1 break; # 裁剪路径
|
| 62 |
-
# rewrite_by_lua_block {
|
| 63 |
-
# local old_path = "/v1/https/generativelanguage.googleapis.com"
|
| 64 |
-
# local new_uri = ngx.var.uri:gsub("^" .. old_path .. "/(.*)$", "/%1")
|
| 65 |
-
# ngx.req.set_uri(new_uri, true) break -- 使用 ngx.req.set_uri 修改 URI
|
| 66 |
-
# }
|
| 67 |
-
# echo "Hello World";
|
| 68 |
-
# echo "Hello World";
|
| 69 |
-
# echo "[" $uri "]";
|
| 70 |
-
# echo "[" $1 "]";
|
| 71 |
-
|
| 72 |
-
# rewrite_by_lua_block {
|
| 73 |
-
# ngx.say('ngx.var.uri: ' .. ngx.var.uri)
|
| 74 |
-
# if ngx.var.uri == "/v1/https/generativelanguage.googleapis.com/v1beta/openai/chat/completions" then
|
| 75 |
-
# ngx.var.uri = "/v1beta/openai/chat/completions"
|
| 76 |
-
# end
|
| 77 |
-
# }
|
| 78 |
-
# 获得需要裁剪掉的路径,比如:/v1/https/generativelanguage.googleapis.com/
|
| 79 |
-
# 由于rewrite不支持变量,或者变量支持不好,所以一直没有达到效果,裁剪后的uri没办法写入ngx.var.uri中(只读)
|
| 80 |
-
#后续此部分有两种方案,
|
| 81 |
-
#方案一(优先):
|
| 82 |
-
# - 直接使用lua进行调用目标服务器,并返回给客户端
|
| 83 |
-
# - 对目标服务器的结果进行分析和统计
|
| 84 |
-
# - 登记api_key的使用情况,并将获得的权益给到api_key提供者
|
| 85 |
-
#方案二(备选):再设立一个 location,将裁剪好的信息转发到新的location
|
| 86 |
-
|
| 87 |
-
# rewrite ^/v1/https/generativelanguage.googleapis.com/(.*)$ /$1 break; # 裁剪路径
|
| 88 |
-
# rewrite_by_lua_block {
|
| 89 |
-
# ngx.say('ngx.var.uri: ' .. ngx.var.uri)
|
| 90 |
-
# }
|
| 91 |
-
# # rewrite ^$will_trim_path(.*)$ /$1 break; # 裁剪路径
|
| 92 |
-
# proxy_pass https://generativelanguage.googleapis.com/;
|
| 93 |
-
# # # proxy_pass $proxy_pass_var;
|
| 94 |
-
# proxy_set_header Host generativelanguage.googleapis.com;
|
| 95 |
-
# # # # 设置其他常用的请求头
|
| 96 |
-
# proxy_set_header X-Real-IP $remote_addr;
|
| 97 |
-
# # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
| 98 |
-
# proxy_set_header X-Forwarded-Proto $scheme;
|
| 99 |
-
# }
|
| 100 |
-
}
|
| 101 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
script.lua
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
ngx.say("Hello, OpenResty and Lua!")
|
|
|
|
|
|
somefile.txt
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
somefile
|
|
|
|
|
|