Linux與雲計算——第二階段Linux服務器架設
第一十一章:代理Proxy服務器架設—Squid代理服務器正向代理和客戶端配置
安裝Squid
安裝Squid來配置代理服務器。
[1] 這是一個通用的轉發代理配置
[root@server ~]# yum -y install squid
[root@server ~]# vi /etc/squid/squid.conf
# line 26: 添加一條新的ACL
acl lan src 192.168.96.0/24
# line 54: 添加一條新的ACL
http_access allow lan
# line 59: 修改
http_port 8080
# 在文件最後添加
request_header_access Referer deny all
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all
# specify hostname
visible_hostname server.example.com
# not display IP address
forwarded_for off
[root@server ~]# systemctl start squid
[root@server ~]# systemctl enable squid
配置Proxy 客戶端
[1] 配置CentOS客戶端
[root@client ~]# vim /etc/profile
# 在文件最後添加 (將代理配置成環境變量)
MY_PROXY_URL="http://server.example.com:8080/"
HTTP_PROXY=$MY_PROXY_URL
HTTPS_PROXY=$MY_PROXY_URL
FTP_PROXY=$MY_PROXY_URL
http_proxy=$MY_PROXY_URL
https_proxy=$MY_PROXY_URL
ftp_proxy=$MY_PROXY_URL
export HTTP_PROXY HTTPS_PROXY FTP_PROXY http_proxy https_proxy ftp_proxy
[root@client ~]# source /etc/profile
# 以上配置就完成了,但是不同的應用可能還需要單獨配置
# 針對YUM
[root@client ~]# vim /etc/yum.conf
# 在最後添加
proxy=http://server.example.com:8080/
# 針對wget
[root@client ~]# vim /etc/wgetrc
# 在最後添加
http_proxy = http://server.example.com:8080/
https_proxy = http://server.example.com:8080/
ftp_proxy = http://server.example.com:8080/