我有一个在端口 2011 上运行的 mitmproxy。我可以单独使用它,使用curl -x http://127.0.0.1:2011 google.com
。但是,我现在想把它放在域名下的 nginx 后面proxy.history.test
。但是,使用 执行curl -x http://proxy.history.test:80 google.com -L -v
失败
* Received HTTP code 400 from proxy after CONNECT
* CONNECT phase completed!
* Closing connection 1
curl: (56) Received HTTP code 400 from proxy after CONNECT
我的nginx.conf
:
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /dev/null;
daemon off;
events {
worker_connections 1024;
}
http {
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
map $http_host $service_port {
hostnames;
default '';
proxy.history.* 2011;
}
proxy_temp_path ./tmp;
access_log /dev/null;
ssl_certificate ./cert.pem;
ssl_certificate_key ./key.pem;
#proxy_set_header Host localhost;
client_body_temp_path ./tmp;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
client_max_body_size 50m;
server {
listen 127.0.0.1:443 ssl;
server_name *.test;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:$service_port;
}
}
server {
listen 127.0.0.1:80;
server_name *.test;
return 302 https://$http_host$request_uri;
}
}
(我必须在 curl 命令中指定,因为否则,它会因为某种原因:80
尝试连接到端口)。1080
答案1
nginx
是反向代理,不是正向代理,不支持HTTP
CONNECT
方法。您需要找到第三方nginx
模块来支持CONNECT
。