“CONNECT 后从代理收到 HTTP 代码 400”,尝试将 mitmproxy 置于 nginx 后面

“CONNECT 后从代理收到 HTTP 代码 400”,尝试将 mitmproxy 置于 nginx 后面

我有一个在端口 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

相关内容