Squid 代理服务器是一个功能丰富的 Web 服务器应用程序,它为网站提供反向代理服务和缓存选项。 这提供了网站的显着加速,并允许在使用时减少加载时间。
Squids 反向代理是一种位于 Internet 和网络服务器(通常在专用网络内)之间的服务,它将入站客户端请求重定向到存储数据以便于检索的服务器。 如果缓存服务器(代理)没有缓存数据,它会将请求转发到实际存储数据的 Web 服务器。 这种类型的缓存允许收集数据并复制存储在不同位置的原始数据值,以提供更轻松的访问。
反向代理通常提供额外的控制层来平滑客户端和 Web 服务器之间的入站网络流量。
Squid 可用作 SSL 请求的缓存服务以及 DNS 查找。 它还可以为多种其他类型的缓存协议提供广泛的支持,例如 ICP, HTCP, 鲤鱼, 也 WCCP. Squid 是许多类型设置的绝佳选择,因为它通过提供大量系统工具以及使用监控框架来提供非常精细的控制 SNMP 为您的缓存需求提供坚实的基础。
在选择用作专用 Squid 缓存代理服务器的计算机系统时,许多用户确保它配置有大量物理内存 (RAM),因为 Squid 维护内存中缓存以提高性能。
安装鱿鱼
让我们首先确保我们的服务器是最新的:
[root@test ~]# apt-get update
Get:1 https://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]Hit:2 https://us.archive.ubuntu.com/ubuntu xenial InReleaseHit:3 https://ppa.launchpad.net/libreoffice/ppa/ubuntu xenial InReleaseGet:4 https://us.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]Get:5 https://us.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]Fetched 325 kB in 0s (567 kB/s)Reading package lists... Done
Next, at the terminal prompt, enter the following command to install the Squid server:
[root@test ~]# apt install squid
Reading package lists... DoneBuilding dependency treeReading state information... DoneThe following packages were automatically installed and are no longer required:linux-headers-4.4.0-141 linux-headers-4.4.0-141-generic linux-image-4.4.0-141-genericUse 'apt autoremove' to remove them.
The following additional packages will be installed:
libecap3 squid-common squid-langpack ssl-cert
Suggested packages:
squidclient squid-cgi squid-purge smbclient ufw winbindd openssl-blacklist
The following NEW packages will be installed:
libecap3 squid squid-common squid-langpack ssl-cert
0 upgraded, 5 newly installed, 0 to remove and 64 not upgraded.
Need to get 2,672 kB of archives.
After this operation, 10.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Fetched 2,672 kB in 0s (6,004 kB/s)
Preconfiguring packages ...
Selecting previously unselected package libecap3:amd64.
(Reading database ... 160684 files and directories currently installed.)
Preparing to unpack .../libecap3_1.0.1-3ubuntu3_amd64.deb ...
Unpacking libecap3:amd64 (1.0.1-3ubuntu3) ...
Selecting previously unselected package squid-langpack.
Preparing to unpack .../squid-langpack_20150704-1_all.deb ...
Unpacking squid-langpack (20150704-1) ...
Selecting previously unselected package squid-common.
Preparing to unpack .../squid-common_3.5.12-1ubuntu7.6_all.deb ...
Unpacking squid-common (3.5.12-1ubuntu7.6) ...
Selecting previously unselected package ssl-cert.
Preparing to unpack .../ssl-cert_1.0.37_all.deb ...
Unpacking ssl-cert (1.0.37) ...
Selecting previously unselected package squid.
Preparing to unpack .../squid_3.5.12-1ubuntu7.6_amd64.deb ...
Unpacking squid (3.5.12-1ubuntu7.6) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for systemd (229-4ubuntu21.16) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up libecap3:amd64 (1.0.1-3ubuntu3) ...
Setting up squid-langpack (20150704-1) ...
Setting up squid-common (3.5.12-1ubuntu7.6) ...
Setting up ssl-cert (1.0.37) ...
Setting up squid (3.5.12-1ubuntu7.6) ...
Skipping profile in /etc/apparmor.d/disable: usr.sbin.squid
Processing triggers for libc-bin (2.23-0ubuntu10) ...
Processing triggers for systemd (229-4ubuntu21.16) ...
Processing triggers for ureadahead (0.100.0-19) ...
就是这样! 安装完成!
配置鱿鱼
默认 Squid 配置文件位于 ‘/等/鱿鱼/ 目录,主配置文件名为“squid.conf”。 该文件包含大量配置指令,可以修改这些指令以改变 Squid 的行为。 以“开头的行#”,被文件注释掉或不被文件读取。 提供这些注释是为了解释相关配置设置的含义。
要编辑配置文件,让我们首先备份原始文件,以防万一出现问题时需要恢复任何更改或使用它来比较新的文件配置。
[root@test ~]# cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
更改 Squid 的默认监听端口
接下来,Squid 代理服务器的默认端口是 3128。如果您希望出于特定原因或必要性修改端口,您可以更改或修改此设置以满足您的需要。 要更改默认 Squid 端口,我们需要编辑 Squid 配置文件并更改“http_port” 值(在第 1599 行)到一个新的端口号。
[root@test ~]# vim /etc/squid/squid.conf
http_port 2946
(暂时保持文件打开…)
更改 Squid 的默认 HTTP 访问端口
接下来,要允许从所有 IP 地址外部访问 HTTP 代理服务器,我们需要编辑“http_access” 指令。 默认情况下,除非我们明确允许,否则 HTTP 代理服务器根本不允许任何人访问!
警告!:多个设置提及 http_access. 我们要修改最后一个条目。
1164 # Deny requests to certain unsafe ports
1165 http_access deny !Safe_ports
...
1167 # Deny CONNECT to other than secure SSL ports
1168 http_access deny CONNECT !SSL_ports
...
1170 # Only allow cachemgr access from localhost
1171 http_access allow localhost manager
1172 http_access deny manager
...
1186 #http_access allow localnet
1187 http_access allow localhost
...
1189 # And finally deny all other access to this proxy
1190 http_access deny all
# > change to “allow all” <
现在,让我们保存并 close 使用vim的配置文件 :wq 命令。
定义 Squid 侦听的默认 NIC 卡
如果您希望 Squid 侦听特定 NIC(在具有多个 NIC 卡的服务器中),您可以使用 Squid 将侦听的 NIC 的 IP 地址更新配置文件。
为了 example,我们可以把它改成10.1.1.5:3128的内部IP
定义谁可以访问代理服务器
接下来,我们将设置允许谁访问我们的 Squid 代理。 找到 http_access 部分(应该从第 1860 行开始)并取消注释以下两行:#acl our_networks src 10.1.1.0/16 10.1.2.0/16
#http_access allow our_networks
-- VVV change to VVV --
acl our_networks src 10.1.1.0/16 10.1.2.0/16
http_access allow our_networks
您需要将 IP 范围 (10.1.1.0/16 10.1.2.0/16) 修改为您自己的内部 IP,以匹配您的网络使用的内容,除非您有多个可以使用的子网。 (网络掩码在此处进一步解释.)
定义可访问代理的时间
您可以从字面上控制访问代理服务器的时间! ACL 部分开始于 第 673 行:671 # none
要进行设置,让我们将此信息添加到 ACL 部分的底部 /etc/squid/squid.conf 文件:
672
673 # TAG: acl
674 # Defining an Access List
675 #
acl BYNSS src 10.1.10.0/24
诚然,这是一个 example 使用 液体网 作为企业名称,但您可以使用任何名称。
acl BYNSS time M T W T F 9:00-17:00
其他 ACL 选项包括:
***** ACL TYPES AVAILABLE *****
711 #
712 # acl aclname src ip-address/mask ... # clients IP address [fast]
713 # acl aclname src addr1-addr2/mask ... # range of addresses [fast]
714 # acl aclname dst [-n] ip-address/mask ... # URL host's IP address [slow]
715 # acl aclname localip ip-address/mask ... # IP address the client connected to [fast]
717 # acl aclname arp mac-address ... (xx:xx:xx:xx:xx:xx notation)
...
730 # acl aclname srcdomain .foo.com ...
731 # # reverse lookup, from client IP [slow]
732 # acl aclname dstdomain [-n] .foo.com ...
733 # # Destination server from URL [fast]
734 # acl aclname srcdom_regex [-i] .foo.com ...
735 # # regex matching client name [slow]
736 # acl aclname dstdom_regex [-n] [-i] .foo.com …
…
… (all the way down to line 989)
…
968 # Example rule allowing access from your local networks.
969 # Adapt to list your (internal) IP networks from where browsing
970 # should be allowed
971 #acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
972 #acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
973 #acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
974 #acl localnet src fc00::/7 # RFC 4193 local private network range
975 #acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
976
977 acl SSL_ports port 443
978 acl Safe_ports port 80 # http
979 acl Safe_ports port 21 # ftp
980 acl Safe_ports port 443 # https
981 acl Safe_ports port 70 # gopher
982 acl Safe_ports port 210 # wais
983 acl Safe_ports port 1025-65535 # unregistered ports
984 acl Safe_ports port 280 # http-mgmt
985 acl Safe_ports port 488 # gss-http
986 acl Safe_ports port 591 # filemaker
987 acl Safe_ports port 777 # multiling http
988 acl CONNECT method CONNECT
989
所有 Squid 配置选项
全面核算 鱿鱼可用配置文件 可以在这些链接中找到。 (确保您计划花一些时间,因为那里有很多信息)
重启鱿鱼
完成这些更改后,让我们重新启动 Squid 服务以重新加载配置文件。
[root@test ~]# systemctl restart squid.service
Squid 的其他重要文件位置

更多关于鱿鱼的信息
我们能帮你什么吗?
我们在托管方面最有帮助的人可以提供有关 Squid 以及如何在我们的特定环境中使用它的清晰和更多信息。 我们的支持团队包含许多对网络托管技术有深入了解的人才,尤其是本文中讨论的那些。 如果您对此处概述的步骤感到不自在,我们只需一个电话、聊天或票证即可为您提供信息以引导您完成整个过程。 今天让我们为您提供帮助!