返回列表 发帖

用Squid搭建带密码认证的http匿名代理服务器

先前发了《使用nginx搭建带密码认证的http正向代理》一文,但是发现在使用密码认证的时候每访问一个页面都要输入一次密码,非常麻烦,因为nginx没有像squid一样有credentialsttl选项可以设置验证的间隔时间,无奈之余希望在以后的版本中能有吧。

不多说了,直接上步骤吧:

一、安装squid
  1. # apt-get -y install squid  #Debian/Ubuntu
  2. # yum -y install squid      #RedHat/CentOS
复制代码

二、生成认证文件
  1. # htpasswd -cb /etc/squid/passwd username password
复制代码

三、备份并创建新的配置文件:
  1. # mv /etc/squid/squid.conf /etc/squid/squid.conf.back
  2. # vi /etc/squid/squid.conf
复制代码

输入以下内容:

http_port 3128
#
#cache_mem 128 MB
#cache_dir ufs /var/spool/squid 100 16 256
#
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm Squid proxy-caching web server
auth_param basic credentialsttl 12 hours
auth_param basic casesensitive off
#
acl ncsa_users proxy_auth REQUIRED
acl all src all
header_access Via deny all
header_access X-Forwarded-For deny all
http_access allow ncsa_users
http_access deny all


四、启动squid
  1. # /etc/init.d/squid start
  2. # chkconfig squid on    #RedHat/CentOS中需要手动将服务加入开机启动
复制代码

关于文件描述符的补充说明:

默认情况下Linux的文件描述符为1024个,大负载的情况下这一点文件提示符是不够的。
  1. # ulimit -n #查看当前文件描述符数量
  2. # ulimit -HSn 51200 #修改文件描述符数量
  3. #写入配置文件,使配置永久生效:
  4. # echo "* soft nofile 51200" >> /etc/security/limits.conf
  5. # echo "* hard nofile 51200" >> /etc/security/limits.conf
复制代码

一个检测是否使用代理的网站:
http://www.iprivacytools.com/proxy-checker-anonymity-test/

如果使用高匿代理访问这个网页则不会被检测出使用代理

TOP

一般来说,我们的服务器不止一个IP地址,这个时候我们可能会需要多个IP作为出口地址。

不过默认情况下,你不管使用哪一个代理服务器的的IP,出口地址都是主IP的地址。其实只要做一些小小的改动就可以实现多IP出口的代理。

1.打开路由功能
  1. # sed -i 's/net.ipv4.ip_forward = 0/net.ipv4.ip_forward = 1/g' /etc/sysctl.conf
  2. # sysctl -p
复制代码

2. 定义使用不同IP作为出口地址的方式,可以按用户、按组、按访问IP等多种方式,我们这里使用按不同用户来定义的方式
  1. acl user1 proxy_auth user1
  2. acl user2 proxy_auth user2
复制代码

3. 定义出口IP
  1. tcp_outgoing_address 192.168.0.10 user1
  2. tcp_outgoing_address 192.168.0.11 user2
复制代码

4.增加用户user1和user2
  1. htpasswd -cb /etc/squid/passwd user1 password1
  2. htpasswd -b /etc/squid/password user2 password2
复制代码

5.贴一个完整的配置文件
  1. http_port 3218
  2. #
  3. auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd
  4. auth_param basic children 5
  5. auth_param basic realm Squid proxy-caching web server
  6. auth_param basic credentialsttl 2 hours
  7. auth_param basic casesensitive off
  8. #
  9. acl user1 proxy_auth user1
  10. acl user2 proxy_auth user2
  11. #
  12. tcp_outgoing_address 192.168.0.10 user1
  13. tcp_outgoing_address 192.168.0.11 user2
  14. #
  15. acl all src all
  16. header_access Via deny all
  17. header_access X-Forwarded-For deny all
  18. http_access allow user1
  19. http_access allow user2
  20. http_access deny all
复制代码

6.重启squid
  1. # service squid restart
复制代码

TOP

返回列表