当前位置: 首页 > 互联网 > 正文

如何使用Squid作为HTTP代理

Squid是一个多用途和高自由度的代理/缓存软件。本教程将介绍怎样使用Squid作为HTTP代理。需要注意的是,代理技术不能完全保证数据和流量安全;如果您需要更安全的数据访问,可以考虑采用架设SSH通道等其他手段。企业网站管理系统本文采用的系统环境是CentOS 6.4, 在CentOS 6其他版本、CentOS 7、Fedora较新版本上均应适用,CentOS 5上未做测试,若您在CentOS 5的服务器上测试本教程则可能需要添加或者更新CentOS源。Debian类的系统未做测试,感兴趣的朋友可以自行搜索测试。

  安装Squid
  Squid软件包是包含在CentOS源中的,因此,我们只需使用SSH连接到您的服务器,执行下面的指令:
  sudo yum update
  sudo yum install squid
  安装完毕后,备份squid配置文件,以防误操作:
  sudo cp /etc/squid/squid.conf /etc/squid/squid.conf.qing.su
  配置Squid使其运行为HTTP代理
  Squid套件可以作为HTTP proxy来绕过部分内网中的不安全因素,并可以在外网中掩盖身份,从而达到安全访问互联网的目的。下面介绍Squid的配置,两种验证方法请任选一种(个人推荐您选择第二种验证方式,因为在大部分情况下您有可能无法获得一个固定的客户端IP地址)。
  1,基础验证设置
  这一节包含了最简单的将Squid配置为HTTP代理的方法,此方法仅仅验证客户端IP。
  (1) 打开Squid配置文件 /etc/squid/squid.conf,添加下面的行:
  acl client src 12.34.56.78 http_access allow name1
  若您有多个IP地址,需在此逐一添加,并将上述行中的name1和12.34.56.78替换成用以区分的任意计算机名和您的客户端的IP地址。
  (2) 添加完毕并保存后,执行下列指令重启Squid服务器:
  sudo service squid restart
  此时,在客户端的电脑上,您已经可以配置您的浏览器中的代理服务器设置并通过这个服务器上网了。
  2,高级验证设置。
  这一节包含了通过用户名和密码来验证Squid代理服务的配置方法。
  (1) 您需要获取htpasswd工具。如果您已经在VPS上安装了Apache服务器软件,就无需额外安装了。若没有,您需要执行下面的指令安装此工具:
  sudo yum install httpd-tools
  (2) 执行下列指令,新建文件以存储Squid用户名和密码,并变更文件属主:
  sudo touch /etc/squid/squid_passwd
  sudo chown squid /etc/squid/squid_passwd
  (3) 下面我们新建用户并设置密码。执行下面的指令,将user1替换为你需要建立的用户名:
  sudo htpasswd /etc/squid/squid_passwd user1
  您将被提示输入新密码并重复输入一次。此时我们建立好了一个用户。
  (4) 打开Squid配置文件/etc/squid/squid.conf,添加下面语句以将用户名-密码文件关联到Squid中:
  auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/squid_passwd
  acl ncsa_users proxy_auth REQUIRED
  http_access allow ncsa_users
  (5) 添加完毕后保存并关闭文件,执行下面的命令以重启Squid:
  sudo service squid restart
  添加其他的用户可以重复使用上述的方法。若要删除某用户,则编辑上述的密码文件,删掉对应用户名的那一行,保存并重启服务即可。此时,您已经可以在客户端的电脑上配置浏览器的代理服务器设置并通过这台VPS上网了。
  实现外网访问的匿名化
  为了实现外网访问的匿名化从而做到安全上网,您需要在Squid配置文件中添加下列语句。使用文本编辑器打开配置文件/etc/squid/squid.conf,添加如下行:
  forwarded_for off
  request_header_access Allow allow all
  request_header_access Authorization allow all
  request_header_access WWW-Authenticate allow all
  request_header_access Proxy-Authorization allow all
  request_header_access Proxy-Authenticate allow all
  request_header_access Cache-Control allow all
  request_header_access Content-Encoding allow all
  request_header_access Content-Length allow all
  request_header_access Content-Type allow all
  request_header_access Date allow all
  request_header_access Expires allow all
  request_header_access Host allow all
  request_header_access If-Modified-Since allow all
  request_header_access Last-Modified allow all
  request_header_access Location allow all
  request_header_access Pragma allow all
  request_header_access Accept allow all
  request_header_access Accept-Charset allow all
  request_header_access Accept-Encoding allow all
  request_header_access Accept-Language allow all
  request_header_access Content-Language allow all
  request_header_access Mime-Version allow all
  request_header_access Retry-After allow all
  request_header_access Title allow all
  request_header_access Connection allow all
  request_header_access Proxy-Connection allow all
  request_header_access User-Agent allow all
  request_header_access Cookie allow all
  request_header_access All deny all
  添加完毕后保存文件,并重启Squid:
  sudo service squid restart
  至此,Squid作为代理服务器的全部配置已经完成,您可以自由使用了。

最后重启squid,设置开机自启动

1
2
service squid restart
chkconfig squid on

这样就算配置完了。

原文 http://www.25yi.com/wangyesheji/squidhttp-399/

本文链接: http://cn.xxh.me/?p=566 | river 的小宅

该日志由 admin 于2016年07月03日发表在 互联网 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
文章转载请注明: 如何使用Squid作为HTTP代理 | river 的小宅

如何使用Squid作为HTTP代理:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter