| |
| local function decode_uri(uri) |
| local decoded = ngx.unescape_uri(uri) |
| return decoded |
| end |
|
|
| |
| local request_uri = ngx.var.request_uri |
| ngx.log(ngx.DEBUG, "完整请求URI: ", request_uri) |
|
|
| |
| local _, _, target_path = string.find(request_uri, "^/proxy/(.*)") |
| ngx.log(ngx.DEBUG, "提取的目标路径: ", target_path or "nil") |
|
|
| if not target_path or target_path == "" then |
| ngx.status = 400 |
| ngx.say("错误: 未提供目标URL") |
| return ngx.exit(400) |
| end |
|
|
| |
| local target_url = decode_uri(target_path) |
| ngx.log(ngx.DEBUG, "解码后的目标URL: ", target_url) |
|
|
| if not target_url or target_url == "" then |
| ngx.status = 400 |
| ngx.say("错误: 无法解析目标URL") |
| return ngx.exit(400) |
| end |
|
|
| |
| ngx.log(ngx.STDERR, "代理请求: ", target_url) |
|
|
| |
| ngx.var.target_url = target_url |
|
|
| |
| return |