Squid Proxy Server 是一個功能豐富的 Web 服務器應用程序,可為您的網站提供反向代理服務和緩存選項。這將顯著加快您的網站並減少使用時的加載時間。
Squids 反向代理是一種位於 Internet 和 Web 服務器(通常在專用網絡中)之間的服務,它將入站客戶端請求重定向到存儲數據以便於檢索的服務器。如果緩存服務器(代理)沒有緩存數據,它會將請求轉發到實際存儲數據的 Web 服務器。這種類型的緩存允許您收集數據並複制存儲在不同位置的原始數據值,以便於訪問。
反向代理通常提供額外的控制層來平滑客戶端和 Web 服務器之間的入站網絡流量。
Squid 可用作 SSL 請求和 DNS 查找的緩存服務。它還廣泛支持其他幾種類型的緩存協議,包括: ICP, HTCP, 鯉魚, 還 世界共產黨.Squid 通過提供大量系統工具和使用的監控框架提供非常細粒度的控制,使其成為多種設置的理想選擇。 網絡管理協議 它為您的緩存需求提供了堅實的基礎。
在選擇計算機系統作為專用的 Squid 緩存代理服務器時,許多用戶發現它配置了大量的物理內存 (RAM),因為 Squid 會維護內存中的緩存以提高性能。確認。
安裝魷魚
首先,讓我們確保服務器是最新的。
[[email protected] ~]# 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:
[[email protected] ~]# 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 的行為。#“,或者註釋掉或者不被文件讀取。提供這些註釋是為了解釋相關配置設置的含義。
要編輯配置文件,首先備份原始文件並撤消更改或使用它來比較新的文件配置,以防出現問題。
[[email protected] ~]# cp /etc/squid/squid.conf /etc/squid/squid.conf.bak
更改 Squid 的默認監聽端口
其次,Squid 代理服務器的默認端口是 3128。如果您想出於任何特定原因或需要更改端口,您可以根據需要更改或修改此設置。要更改默認 Squid 端口,請編輯 Squid 配置文件並添加http_port‘ 值(第 1599 行)到新的端口號。
[[email protected] ~]# 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” <
現在讓我們使用 vim 保存並關閉配置文件 :wq 命令。
定義 Squid 偵聽的默認 NIC 卡
如果您希望 Squid 偵聽特定 NIC(在具有多個 NIC 卡的服務器上),您可以使用 Squid 偵聽的 NIC 的 IP 地址更新配置文件。
例如,您可以將其更改為內部 IP 10.1.1.5:3128。
定義誰可以訪問代理服務器
接下來,配置允許哪些用戶訪問 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,以匹配您網絡中使用的 IP。 (網絡掩碼在此處進一步解釋.)
定義可以聯繫到代理的時間
您真的可以控制何時訪問代理服務器。 ACL 部分是 第 673 行:671 # none
要進行配置,讓我們將此信息添加到 ACL 部分的底部 /etc/squid/squid.conf 文檔:
672
673 # TAG: acl
674 # Defining an Access List
675 #
acl CodePre src 10.1.10.0/24
當然這是一個示例用法 液體網 作為公司名稱,但您可以使用任何名稱。
acl CodePre 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 服務以重新加載配置文件。
[[email protected] ~]# systemctl restart squid.service
其他重要 Squid 文件的位置

關於魷魚
你能幫助我嗎?
託管方面最有幫助的人可以提供有關 Squid 以及如何在您的特定環境中使用它的清晰和詳細的信息。我們的支持團隊包括許多對網絡託管技術有深刻理解的優秀成員,尤其是本文中討論的技術。如果您對按照此處列出的步驟感到不自在,只需打個電話、聊天或提供信息以指導您完成整個過程。今天就讓我們來幫你吧!