阿里云 centos7 服务器搭建代理IP

注意:开始前先去阿里云开放自己的端口,例如你是默认的3128,则去阿里云开启3128端口,

我使用的是3888端口,我开启的是3888端口

搭建服务器:

1、yum 安装 squid 和httpd-tools  (-y 全自动安装)

#更新yum
yum update

yum install squid -y
yum install httpd-tools -y

2.生成密码文件

mkdir /etc/squid3/
#username 是用户名
htpasswd -cd /etc/squid3/passwords username
#提示输入密码,输入即可 注意密码不要超过 8 位

#测试密码文件
/usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
# 输入 用户名 密码
username password
# 提示 OK 说明成功,ERR 是有问题,请检查一下之前步骤
OK
# 测试完成,crtl + c 打断

 

3.配置squid.conf文件

vi /etc/squid/squid.conf

配置文件加入:

#ncsa_auth的路径要找到自己安装的地方。一般在/usr/lib/squid/或者/usr/lib/squid3/视版本而定。

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
acl ncsa_users  proxy_auth REQUIRED
http_access allow ncsa_users

#把http_access allow localnet , http_access allos localhost屏蔽掉。
 
# 设置来源IP白名单,增加的这两行要在 http_access deny all 前面,因为squid配置文件是从上往下读的

acl localnet src 222.93.8.140
http_access allow client
# And finally deny all other access to this proxy
http_access deny all

4.修改完配置文件后启动

# 先初始化一下
squid -z
# 启动
systemctl start squid.service
# 停止
systemctl stop squid.service
# 重启
#配置开机自启动
systemctl enable squid.service

附录:  /etc/squid/squid.conf完整代码

#
# Recommended minimum configuration:
#

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

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

#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

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

# 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

auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
acl ncsa_users  proxy_auth REQUIRED
http_access allow ncsa_users

acl localnet src 222.93.8.140
# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
lhttp_port 3888

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256

# 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

 

    原文作者:renyiisgod
    原文地址: https://blog.csdn.net/qq_27598243/article/details/89713220
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞