天天看點

Linux與雲計算——第二階段 第一十一章:代理Proxy伺服器架設—Squid進行基礎認證

Linux與雲計算——第二階段Linux伺服器架設

第一十一章:代理Proxy伺服器架設—Squid進行基礎認證

基礎認證

配置基礎認證并且限制使用者必須使用認證。

[1] 安裝軟體包以便包含htpasswd.

[root@server ~]# yum -y install httpd-tools

[2] 配置Squid來設定Basic Auth.

[root@server ~]# vi /etc/squid/squid.conf

acl CONNECT method CONNECT

# line 26: 添加以下行來開啟認證

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/.htpasswd

auth_param basic children 5

auth_param basic realm Squid Basic Authentication

auth_param basic credentialsttl 5 hours

acl password proxy_auth REQUIRED

http_access allow password

# 添加一個使用者

[root@server ~]# htpasswd -c /etc/squid/.htpasswd jeffrey

[root@server ~]# systemctl restart squid

[3] 配置用戶端.

[root@client ~]# vi /etc/profile

# add follows to the end

# username:password@proxyserver:port

MY_PROXY_URL="http://jeffrey:[email protected]: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/

proxy_username=jeffrey

proxy_password=redhat

# 針對wget

[root@client ~]# vi /etc/wgetrc

http_proxy = http://server.example.com:8080/

https_proxy = http://server.example.com:8080/

ftp_proxy = http://server.example.com:8080/