yun 发表于 2017-5-1 21:20:01

nginx搭建带密码认证http代理服务器

server {
     listen       8080;
             client_body_timeout 60000;
             client_max_body_size 1024m;
             send_timeout       60000;
             client_header_buffer_size 16k;
             large_client_header_buffers 4 64k;

             proxy_headers_hash_bucket_size 1024;
             proxy_headers_hash_max_size 4096;
             proxy_read_timeout 60000;
             proxy_send_timeout 60000;

     location / {
         auth_basic "Please enter your password:";
         auth_basic_user_file /var/www/vhosts/htpasswd;
         resolver 8.8.8.8;
         proxy_pass http://$http_host$request_uri;
     }
} ps:

resolver 8.8.8.8; 代表使用Google DNS来解析域名.
client_body_timeout,large_client_header_buffers 等设置,确保大的请求不会返回400错误.
auth_basic和auth_basic_user_file是身份认证设置.
但这个代理服务器只支持http请求,https会报400错误.
在实际应用中,使用nginx做带密码认证的http正向代理并不合适,因为没有设置密码认证间隔的模块,所以每访问一个页面都要输入一次密码,对于没有安装可以保存密码的代理插件的浏览器用户来说简直就是噩耗.

页: [1]
查看完整版本: nginx搭建带密码认证http代理服务器