在本教程中,我们将向您展示如何在您的 CentOS 7 上安装和配置 Squid。对于那些不知道的人,Squid 是一个支持 HTTP、HTTPS、FTP 等的 Web 缓存代理。 各种组织和互联网提供商使用 Squid 代理来减少带宽并增加响应时间。
本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo
‘ 到命令以获取 root 权限。 我将向您展示在 CentOS 7 服务器上逐步安装 Squid 代理。
在 CentOS 7 上安装 Squid
第 1 步。首先,让我们首先确保您的系统是最新的。
yum -y update
步骤 2. 安装 Squid。
安装 Squid 和相关软件包现在只需运行一个命令即可:
yum install squid
验证并检查 Squid 安装的版本:
squid -v
启动服务并将其设置为在引导时启动:
systemctl enable squid systemctl start squid systemctl status squid
步骤 3. 在 CentOS 7 上配置 Squid。
您现在可以配置 Squid。 配置文件位于以下路径:
nano /etc/squid/squid.conf
# Recommended minimum configuration: auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/squid_passwd acl ncsa_users proxy_auth REQUIRED http_access allow ncsa_users acl manager proto cache_object acl localhost src 127.0.0.1/32 acl to_localhost dst 127.0.0.0/8 0.0.0.0/32 acl SSL_ports port 443 acl Safe_ports port 80 # http acl Safe_ports port 21 # ftp acl Safe_ports port 443 # https acl Safe_ports port 1025-65535 # unregistered ports acl Safe_ports port 280 # http-mgmt acl Safe_ports port 488 # gss-http acl Safe_ports port 591 # filemaker acl Safe_ports port 777 # multiling http acl CONNECT method CONNECT http_access allow manager localhost http_access deny manager http_access deny !Safe_ports http_access deny CONNECT !SSL_ports http_access deny all http_port 3128 hierarchy_stoplist cgi-bin ? coredump_dir /var/spool/squid cache deny all refresh_pattern ^ftp: 1440 20% 10080 refresh_pattern ^gopher: 1440 0% 1440 refresh_pattern -i (/cgi-bin/|?) 0 0% 0 refresh_pattern . 0 20% 4320 icp_port 3130 forwarded_for off request_header_access Allow allow all request_header_access Authorization 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 visible_hostname idroot.us
创建 Squid 可以用来验证用户身份验证的身份验证文件:
htpasswd -b /etc/squid/squid_passwd username password
最后重启squid服务,添加防火墙规则,允许squid 3128端口。
systemctl restart squid firewall-cmd –zone=public –add-port=3128/tcp –permanent firewall-cmd –reload
完成配置部分现在是时候在客户端浏览器中测试浏览指向 squid IP 和默认端口了。
恭喜! 您已成功安装 squid。 感谢您使用本教程在 CentOS 7 系统上安装 squid 代理。 如需更多帮助或有用信息,我们建议您查看 鱿鱼官方网站.