美文网首页
ubuntu apt-get 添加代理、配置squid

ubuntu apt-get 添加代理、配置squid

作者: 不爱吃饭的小孩怎么办 | 来源:发表于2020-05-06 09:44 被阅读0次

squid配置:
##################################
错误的原因在于acl的配置部分出错
在squid.conf中默认只有

Example rule allowing access from your local networks.

Adapt to list your (internal) IP networks from where browsing

should be allowed

acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
而对于外网如202.197.66.*访问内网时,会被拒绝
添加
acl localnet src 202.197.66.0/24 # my own network --belcome
这样一条语句即可

如果要允许所有 则可以通过
acl all src all
http_access allow all
实现放行所有到网关的http请求
我选择全部放行,增加用户权限进行校验:

Squid实现用户名密码,使用HTTPBasicAuth 的方式。 需要htpasswd工具来创建passwd文件 (安装Apache软件,此工具会附带安装, 或者使用 apt-get/yum install http-tools的方式安装此工具)

A. 创建用户‘proxy_username’ 的命令如下:

htpasswd -c /etc/squid/passwd proxy_username
输入相应的密码后,生成 文件 /etc/squid/passwd

  1. 将下述代码添加到/etc/squid/squid.conf 中即配置实用验证的功能:

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
acl auth_user proxy_auth REQUIRED
http_access allow auth_user

  1. 重启squid,使用命令:

service squid restart 或
/etc/init.d/squid restart

客户机添加代理配置:

(1) 需要在/etc/apt/apt.conf中添加以下代码:

Acquire::http::proxy “http://用户名:密码@地址:端口”;
Acquire::ftp::proxy “http://用户名:密码@地址:端口”;
Acquire::https::proxy “http://用户名:密码@地址:端口”;

保存apt.conf文件。

(2)在主目录下的.bashrc文件中添加两行。
在您的.bashrc文件末尾添加如下内容
export http_proxy=http://用户名:密码@地址:端口/
export https_proxy=http://用户名:密码@地址:端口/
export ftp_proxy=http://用户名:密码@地址:端口/

(3)关闭再打开终端,sudo apt-get update 就可以用了

如果不配置第二个步骤,可以通过:
临时设定:

     $ sudo apt-get update -c /etc/apt/apt.conf    其中apt_proxy.conf 内容格式如上所示。
     $ sudo apt-get install -c /etc/apt/apt.conf  nvidia-container-runtime

相关文章

网友评论

      本文标题:ubuntu apt-get 添加代理、配置squid

      本文链接:https://www.haomeiwen.com/subject/werightx.html