ngx_http_proxy_connect_module 带有用户和密码

ngx_http_proxy_connect_module 带有用户和密码

我正在使用 Nginx ngx_http_proxy_connect_module,我想知道是否可以使用用户和密码,如下所示

curl -vvv "ifconfig.me" -x user:password@localhost:8000

这是我的nginx.conf

worker_processes auto;

daemon off;

events { }

http {
    server_names_hash_bucket_size 128;

    server {
        listen 8000;

        resolver 1.1.1.1;

        proxy_connect;
        proxy_connect_allow all;
        proxy_connect_connect_timeout 10s;
        proxy_connect_read_timeout 10s;
        proxy_connect_send_timeout 10s;

        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;

        location / {
            proxy_pass http://$http_host;
            proxy_set_header Host $http_host;
        }
    }
}

测试,没有运气:

curl -vvv "ifconfig.me" -x user:password@localhost:8000

*   Trying 127.0.0.1:8000...* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8000 (#0)
* Proxy auth using Basic with user 'user'
> GET http://ifconfig.me/ HTTP/1.1
> Host: ifconfig.me
> Proxy-Authorization: Basic dXNlcjpwYXNzd29yZA==
> User-Agent: curl/7.68.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 401 Unauthorized
< Server: nginx/1.21.3
< Date: Sat, 30 Oct 2021 18:07:44 GMT
< Content-Type: text/html
< Content-Length: 179
< Connection: keep-alive
* Authentication problem. Ignoring this.
< WWW-Authenticate: Basic realm="Restricted Content"
< 
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.21.3</center>
</body>
</html>
* Connection #0 to host localhost left intact
*

答案1

我最终使用 Squid 作为代理

相关内容