|
|
|
|
|
worker_processes auto |
|
|
events { |
|
|
worker_connections 1024 |
|
|
} |
|
|
|
|
|
http { |
|
|
include mime.types |
|
|
default_type application/octet-stream |
|
|
|
|
|
sendfile on |
|
|
keepalive_timeout 65 |
|
|
|
|
|
lua_package_path '$prefix/lua/?.lua;$prefix/lualib/?.lua;;' |
|
|
|
|
|
server { |
|
|
listen 7860 |
|
|
server_name localhost |
|
|
|
|
|
set $target_proto "" |
|
|
set $target_host "" |
|
|
set $target_path "" |
|
|
|
|
|
|
|
|
location ~ ^/v1/(https?)/([^/]+)(/.*)$ { |
|
|
resolver 8.8.8.8 |
|
|
access_by_lua_block { |
|
|
-- 设置目标变量 |
|
|
ngx.var.target_proto = ngx.var[1] |
|
|
ngx.var.target_host = ngx.var[2] |
|
|
ngx.var.target_path = ngx.var[3] |
|
|
|
|
|
-- 处理特殊字符转义(如路径中的%2F) |
|
|
ngx.var.target_path = ngx.re.gsub(ngx.var.target_path, "\\%2F", "/", "ijo") |
|
|
} |
|
|
proxy_pass $target_proto://$target_host$target_path |
|
|
proxy_set_header Host $target_host |
|
|
|
|
|
proxy_set_header X-Real-IP $remote_addr |
|
|
|
|
|
proxy_set_header X-Forwarded-Proto $scheme |
|
|
} |
|
|
} |
|
|
} |
|
|
|