如何在 CentOS 上安装和配置 Squid 3

在本教程中,我们将向您展示如何在 CentOS 上安装和配置 Squid 3。 对于那些不知道的人,Squid 是一个支持 HTTP、HTTPS、FTP 等的 Web 缓存代理。 各种组织和互联网提供商使用 Squid 代理来减少带宽并增加响应时间。

本文假设您至少具备 Linux 的基本知识,知道如何使用 shell,最重要的是,您将网站托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户下运行,如果不是,您可能需要添加 ‘sudo‘ 到命令以获取 root 权限。 我将向您展示如何在 CentOS Linux 服务器中逐步安装 Squid。

在 CentOS 上安装和配置 Squid 3

步骤 1. 要安装,首先您必须更新 yum 通过键入以下命令来存储库和包:

sudo yum -y update

步骤 2. 在 CentOS 上安装和配置 Squid 3。

使用以下命令安装 squid 包和依赖项:

sudo yum -y install squid

步骤 3. 配置 Squid。

编辑鱿鱼配置文件’/etc/squid/squid.conf

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

步骤 4. 创建 Squid 可用于验证用户身份验证的身份验证文件:

htpasswd -b /etc/squid/squid_passwd username password

例子:

htpasswd -b -c /etc/squid/squid_passwd ranty ratna

恭喜! 您已成功安装 squid。 感谢您使用本教程在 CentOS 系统上安装 squid 代理。 如需更多帮助或有用信息,我们建议您查看 鱿鱼官方网站.