Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxy 代理异常,报错连接超时 #316

Open
charles-liming opened this issue May 16, 2024 · 1 comment
Open

proxy 代理异常,报错连接超时 #316

charles-liming opened this issue May 16, 2024 · 1 comment

Comments

@charles-liming
Copy link

使用了proxy 功能,一直连接超时,下边是日志,就是显示已经走了代理,proxy IP: http://8ec525e5ed1f4586:30102906103665@49.70.150.136:31149, 但是超时,然后我实际测试了代理地址是可用的,测试方式是curl -x http://8ec525e5ed1f4586:158295654881503@117.68.38.165:49668 -I http://47.93.177.135/123.jpg 是可以用的。

2024/05/16 23:41:28 [error] 6#6: *30 lua tcp socket read timed out, client: 172.17.208.11, server: _, request: "GET /?url=http://47.93.177.135/123.jpg HTTP/1.1", host: "172.17.243.208"
2024/05/16 23:41:28 [error] 6#6: *30 [lua] proxy_request.lua:179: proxy_request(): failed to request via proxy: timeout, proxy IP: http://8ec525e5ed1f4586:30102906103665@49.70.150.136:31149, client: 172.17.208.11, server: _, request: "GET /?url=http://47.93.177.135/123.jpg HTTP/1.1", host: "172.17.243.208"
2024/05/16 23:42:28 [error] 6#6: *30 lua tcp socket read timed out, client: 172.17.208.11, server: _, request: "GET /?url=http://47.93.177.135/123.jpg HTTP/1.1", host: "172.17.243.208"
2024/05/16 23:42:28 [error] 6#6: *30 [lua] proxy_request.lua:179: proxy_request(): failed to request via proxy: timeout, proxy IP: http://8ec525e5ed1f4586:250299687038506@180.118.241.215:34324, client: 172.17.208.11, server: _, request: "GET /?url=http://47.93.177.135/123.jpg HTTP/1.1", host: "172.17.243.208"
{ "timestamp": "2024-05-16T23:42:28+08:00", "remote_addr": "172.17.208.11", "body_bytes_sent": 57, "request_time": 121.731, "response_status": 200, "request": "GET /?url=http://47.93.177.135/123.jpg HTTP/1.1", "request_method": "GET", "host": "172.17.243.208","upstream_addr": "","args": "url=http://47.93.177.135/123.jpg","http_x_forwarded_for": "","http_referrer": "", "http_user_agent": "curl/7.61.1", "http_version": "HTTP/1.1", "proxy_ip": "http://8ec525e5ed1f4586:250299687038506@180.118.241.215:34324", "nginx_access": true }
2024/05/16 23:42:28 [error] 6#6: *30 attempt to set status 500 via ngx.exit after sending out the response status 200, client: 172.17.208.11, server: _, request: "GET /?url=http://47.93.177.135/123.jpg HTTP/1.1", host: "172.17.243.208"

@charles-liming
Copy link
Author

我的代码,如下
144 local user, pass, host, port = string.match(proxy_ip.http, "http://([^:]+):([^@]+)@([^:]+):(%d+)")
145
146 -- 确保端口号是数字
147 port = tonumber(port)
148 if not port then
149 ngx.log(ngx.ERR, "Invalid port number.")
150 return
151 end
152
153 -- 创建代理认证字符串
154 local credentials = ngx.encode_base64(user .. ":" .. pass)
155 local proxy_auth = "Basic " .. credentials
156
157 -- 设置代理
158 httpc:set_proxy_options({
159 http_proxy = "http://" .. host .. ":" .. port,
160 http_proxy_authorization = proxy_auth
161 })
162
163
164 local res, err = httpc:request_uri(upstream_url, {
165 method = method,
166 headers = {
167 ["Host"] = host,
168 ["User-Agent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
169 ["Accept"] = "/",
170 ["Referer"] = upstream_url,
171 ["Connection"] = "keep-alive",
172 },
173 body = ngx.req.get_body_data(),
174 ssl_verify = false,
175 -- proxy = proxy_ip.http -- Assuming you want to use the HTTP proxy
176 })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant