# 注意事项:
```txt
1、使用http协议
2、使用过socks5协议(仅个人使用失败,如果有成功的,麻烦告知下,谢谢)
3、代理的服务器要能访问中央仓库
4、代理的服务器上要安装squid软件(linux系统的http代理服务器)
5、<你想要的端口> 这个里面是文字的要将<你想要的端口>整个替换成里面说明的文字
```
# 使用docker在服务器上安装squid
## 第一步:安装squid镜像,并运行,对应主机端口是3128,如果使用其他接口可以将第一个3128改成你想要的端口
docker run -d -p <你想要的端口>:3128 minimum2scp/squid
```sh
docker run -d --name squid -p 3128:3128 minimum2scp/squid
```
## 第二步:进入容器
```sh
docker exec -it squid /bin/bash
```
## 第三步:设置访问权限(指定用户密码登录 http basic认证)
首先要生成一个密码文件,用到htpasswd,是apache服务自带的一个命令工具。如果没有使用apache服务器,例如使用nginx等,可能手头没有这个命令行工具,可以使用[在线版生成器](https://tool.oschina.net/htpasswd)
## 第四步:将生成的字符串赋值到/usr/lib/squid/passwd
```sh
vi /usr/lib/squid/passwd
```
## 第五步:粘贴(账号test,密码test),最后(:wq)进行保存
```sh
test:$apr1$Z99uT4fd$3b9JJsvCNYw7FoNpqdfor/
```
## 第六步:密码文件准备好以后编辑配置文件启用密码认证
```sh
vi /etc/squid/squid.conf
```
找到 http_access allow localhost 这一行,删掉,或注释掉
接着往下找到 http_access deny all 这一行,删掉,或注释掉
添加一行 http_access allow auth_user改完后大概是这样的
```sh
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
#http_access allow localnet
#http_access allow localhost
# And finally deny all other access to this proxy
#http_access deny all
http_access allow auth_user
```
(注意,根据版本不同,/usr/lib/squid/basic_ncsa_auth可能会是/usr/lib/squid/ncsa_auth,自己检查一下。)
继续找到auth_param basic部分的设置,默认是none,添加2行。改完后大概是这样的
```sh
##auth_param basic program <uncomment and complete this line>
##auth_param basic children 5 startup=5 idle=1
##auth_param basic realm Squid proxy-caching web server
##auth_param basic credentialsttl 2 hours
#Default:
# none
auth_param basic program /usr/lib/squid/basic_ncsa_auth /usr/lib/squid/passwd
acl auth_user proxy_auth REQUIRED
```
设置完成了
## 第七步:找到maven的安装文件夹D:\api\apache-maven-3.0.5\conf的conf目录下的settings.xml
## 第八步:找到setting.xml的proxies
```sh
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
```
## 第九步:修改添加
```sh
<proxy>
<id>ss</id>
<active>true</active>
<protocol>http</protocol>
<username>test</username>
<password>test</password>
<host><服务器地址></host>
<port><端口号></port>
</proxy>
```
参考:
版权属于:芒果爱吃胡萝卜
本文链接:http://blog.mangolovecarrot.net/2021/05/07/275
转载时须注明出处及本声明