资讯专栏INFORMATION COLUMN

使用Docker搭建Squid代理服务器

syoya / 2638人阅读

摘要:已发出请求,正在等待回应长度正在保存至用时已保存认证失败正在连接已连接。参考参考一参考二

title: Docker搭建代理服务器
tags:
    - Squid
categories:
    - Linux

[TOC]

环境说明
项目 说明
系统 Deepin 15.5
步骤

安装Docker

安装Squid容器

生成认证文件

配置Squid服务器

启动Squid容器

设置代理地址

使用代理

安装Docker
# 下载安装脚本
$ curl -fsSL get.docker.com -o get-docker.sh

# 安装 docker
$ sudo sh get-docker.sh

# 启动 docker
$ sudo service docker start 
安装Squid容器
# 从docker hub下载容器
$ docker pull sameersbn/squid

# 在docker中创建容器
$ docker run --name squid -d --restart=always 
  --publish 3128:3128 
  --volume /srv/docker/squid/cache:/var/spool/squid3 
  sameersbn/squid
配置用户名密码认证
# 生成认证文件
$ sudo htpasswd squid_passwd your-username
## 在这里输入两次密码

# 将认证文件拷贝至容器
$ sudo docker cp squid_passwd squid:/etc/squid3/
Squid配置

配置文件大概如下

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
acl localnet src fc00::/7       # RFC 4193 local private network range
acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
acl localnet src 0.0.0.0/0.0.0.0
acl localnet src 0.0.0.0/8

acl SSL_ports port 443
acl Safe_ports port 80        # http
acl Safe_ports port 21        # ftp
acl Safe_ports port 443        # https
acl Safe_ports port 70        # gopher
acl Safe_ports port 210        # wais
acl Safe_ports port 1025-65535    # unregistered ports
acl Safe_ports port 280        # http-mgmt
acl Safe_ports port 488        # gss-http
acl Safe_ports port 591        # filemaker
acl Safe_ports port 777        # multiling http
acl CONNECT method CONNECT

# username&password auth config
auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid3/squid_passwd
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users


http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access allow localhost manager
http_access deny manager
http_access deny to_localhost
http_access allow localnet
http_access allow localhost
http_access deny all
http_port 3128

cache_dir ufs /var/spool/squid3 100 16 256
coredump_dir /var/spool/squid3

refresh_pattern ^ftp:        1440    20%    10080
refresh_pattern ^gopher:    1440    0%    1440
refresh_pattern -i (/cgi-bin/|?) 0    0%    0
refresh_pattern (Release|Packages(.gz)*)$      0       20%     2880
refresh_pattern .        0    20%    4320

将配置文件导入Squid容器

$ sudo docker cp squid-simple.conf squid:/etc/squid3/squid.conf

配置文件生成说明

# 从Squid容器中导出默认配置文件
$ sudo docker cp squid:/etc/squid3/squid.conf ./

# 去掉注释
$ sudo awk "/^[^#]/" squid.conf > squid-simple.conf

# 编辑配置文件
$ sudo vim squid-simple.conf
## 在这里添加几行
## acl localnet src 0.0.0.0/0.0.0.0
## acl localnet src 0.0.0.0/8
## auth_param basic program /usr/lib/squid3/basic_ncsa_auth /etc/squid3/squid_passwd
## acl ncsa_users proxy_auth REQUIRED
## http_access allow ncsa_users
启动或重启容器
# 启动容器
$ sudo docker start squid

# 重启容器
$ sudo docker restart squid
使用代理
## 代理地址
# http://{your-username}:{your-password}@{your-ip OR domain-name}:3128
## 例如
# http://root:root@202.118.1.100:3128

## 在Linux终端中使用代理
export ftp_proxy=http://{your-username}:{your-password}@{your-ip OR domain-name}:3128
export http_proxy=http://{your-username}:{your-password}@{your-ip OR domain-name}:3128
export https_proxy=http://{your-username}:{your-password}@{your-ip OR domain-name}:3128
## 例如
export ftp_proxy=http://root:root@202.118.1.100:3128
export http_proxy=http://root:root@202.118.1.100:3128
export https_proxy=http://root:root@202.118.1.100:3128
演示 代理成功
bovenson@ThinkCentre:~/Tmp$ export http_proxy=http://***:***@***.***.***.***:3128
bovenson@ThinkCentre:~/Tmp$ export https_proxy=http://***:***@***.***.***.***:3128
bovenson@ThinkCentre:~/Tmp$ wget www.baidu.com
--2018-04-15 00:40:52--  http://www.baidu.com/
正在连接 ***.***.***.***:3128... 已连接。
已发出 Proxy 请求,正在等待回应... 200 OK
长度:2381 (2.3K) [text/html]
正在保存至: “index.html.1”

index.html.1                             100%[==================================================================================>]   2.33K  --.-KB/s  用时 0s      

2018-04-15 00:40:52 (333 MB/s) - 已保存 “index.html.1” [2381/2381])
认证失败
bovenson@ThinkCentre:~/Tmp$ export http_proxy=http://***.***.***.***:3128
bovenson@ThinkCentre:~/Tmp$ export https_proxy=http://***.***.***.***:3128
bovenson@ThinkCentre:~/Tmp$ wget www.so.com
--2018-04-15 00:42:01--  http://www.so.com/
正在连接 ***.***.***.***:3128... 已连接。
已发出 Proxy 请求,正在等待回应... 407 Proxy Authentication Required
2018-04-15 00:42:01 错误 407:Proxy Authentication Required。
参考

参考一

参考二

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/27281.html

相关文章

  • 使用squid在阿里云务器(centos7)上搭建自己的代理务器

    摘要:我记录的是用来完成的代理服务器。安装检测是否安装出现以上提示说明没有安装。安装配置文件修改在结尾处追加注释掉默认的创建交换目录启动查看端口状态如果出现一下截图,表示配置成功,停止阿里云的安全组别忘记设置我记录的是用squid来完成的代理服务器。   安装 检测是否安装: # which squid /usr/bin/which: no squid in (/usr/local/sbin:/u...

    meteor199 评论0 收藏0
  • centos6/7 squid 安装教程

    摘要:因为内网限制,需要通过搭建代理服务器进行访问。这篇文章主要把我搭建的过程分享出来。那么现在开始的配置之旅。下几篇文章,我将深入介绍和的配置。 因为内网限制,需要通过搭建squid代理服务器进行访问。这篇文章主要把我搭建的过程分享出来。 /* 我这边主要通过rpm安装,具体的源码编译安装自己去看官网吧 */ /* 添加 yum squid源 */ /*参考ref http://wiki....

    hiyayiji 评论0 收藏0
  • Nginx配置参数中文说明

    摘要:此篇文章参照配置参数中文详细说明一文,动手操作整理文档,尽可能的详尽。这里在主机上通过浏览器访问这个站点的时候,会根据来访的主机的值,负载均衡到和服务器上。如果其中一个服务器无效后,负载均衡服务器会自动将请求转发到正常的服务器。 此篇文章参照Nginx配置参数中文详细说明一文,动手操作整理文档,尽可能的详尽。 Nginx配置参数中文详细说明 #定义Nginx运行的用户和用户组 user...

    bawn 评论0 收藏0

发表评论

0条评论

syoya

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<