Tommonkey

All greatness comes from a brave beginning

0%

HTTPS代理服务器搭建与配置

代理类型

代理相当于一个中介,我们委托中介去帮我们做一些事情,我们在幕后操作就OK了。代理的类型大致分为

  • 透明代理:使用此种代理方式的缺点就是数据包的https头会有X-Forwarded-For字段,通过该字段别人是可以查到我们真实的IP的,风险较大,除非你使用该代理方式做的事情是没有危害的事情。否则是不建议的!
  • 普通代理:相比较于透明代理,该代理隐藏了X-Forwarded-For字段,虽然安全性上提高了一些,但通过抓取数据包,分析包中的via字段也是可以找到我们的。
  • 匿名代理:强烈推荐该代理类型,安全性大大提高,同时隐藏了上述了两种字段。想查到背后的真实IP还是挺难的。

HTTPS代理服务器搭建

环境

这里服务器端的操作系统为CentOS 7.5 版本,同时这里选用的开源的squid作为代理程序。

服务器端安装部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# yum安装squid
yum install -y squid

# yum按照htpasswd
yum install httpd

# 进入squid.conf文件进行配置
vim /etc/squid/squid.conf

# 设置允许访问的端口
acl Safe_ports port ports

# 设置代理监听端口,squid默认是3128
http_port port

# 代理类型设置
request_header_access Via deny all
request_header_access X-Forwarded-For deny all
request_header_access From deny all

# 设置访问认证
find / -name htpasswd
# 找到该目录并进入执行如下命令设置用户名与密码
./htpdpwad -c /etc/squid/password username
#找到用户验证程序,不同版本验证程序名字可能稍微有差异!找到后记住该路径!
find / -name base_ncsa_auth
# 进入squid.conf进行认证用户的配置
# 添加如下内容(不同环境,路径可能有差异!)
auth_param basic program /usr/lib64/squid/ncsa_auth /etc/squid/password
# 设置认证程序数
auth_param basic children 10
# 认证有效时间
auth_param basic credentialsttl 100 hours
# 设置允许认证的用户
acl auth_user proxy_auth tommonkey
http_access allow auth_user

按照个人的喜好或需要进行配置就好,比如需要添加一个访问认证的功能,这样只有我允许的账号才能有资格使用我的代理服务器资源。这里贴出我的配置如下(进入squid.conf文件下配置):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# allow conntion port
acl Safe_ports port 1-65535
acl CONNECT method CONNECT

# Only allow cachemgr access from localhost
http_access allow localhost manager

# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
http_access allow localhost

# Squid normally listens to port 3128
http_port 5005

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320

### proxy http header setting
request_header_access Via deny all
request_header_access X-Forwarded-For deny all
request_header_access From deny all

# setting auth
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/password
auth_param basic children 10
auth_param basic credentialsttl 100 hours
acl auth_user proxy_auth tommonkey
http_access allow auth_user

设置完成后,启动squid,开始运行:

1
2
3
语法检查:squid -k parse
初始化缓存目录:squid -z
启动:systemctl start squid.service

噢,对了,记得对配置一下防火墙对squid监听端口放行:

1
2
3
firewall-cmd --zone --add-port=3128/tcp --permanent
firewall-cmd --list-port
firewall-cmd --reload

squid的访问日志存放在

1
/var/log/squid/access.log

客户端连接

这里其实并没有固定的方式连接,根据你的喜好,可以直接使用系统中的代理设置来连接,也可以使用如proxifier代理软件来连接

测试

这里提供如下网站测试代理服务器是否正常工作,如果正常工作访问这些网站就会返回的是你代理服务器的IP

1
2
https://icanhazip.com/
http://httpbin.org/ip

over!!!

奖励作者买杯可乐?