Linux代理服务器配置

说明:一般在工作中,公司内部使用内网的话,服务器也做了设置,不能直接拉取阿里、网易等的镜像,需要通过配置代理服务器进行转发访问,也就是说,服务器首先访问代理服务器,然后通过代理服务器拉取阿里、网易等的镜像信息。

1.安装squid工具

yum install squid -y

在这里插入图片描述

2.修改配置文件

vim /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
# 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 allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# 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
# 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
                                                        

3.查看监听的端口

netstat -ntl

在这里插入图片描述

4.关闭防火墙

systemctl stop firewalld

5.在客户端转发代理服务器的ip和端口

export http_proxy=http://121.36.61.234:3128
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
代码是工作之余写的,代码分为转发服务器和代理服务器 先说转发服务器 转发服务器其实也可以说成是重定向服务器,比如转发服务器监听80端口,如果有浏览器用户访问服务器IP(浏览器默认请求80端口),转发服务器接收到浏览器用户的请求后,便把浏览器用户的请求重定向到本机的其它端口或者处于同一网段其它机器的指定端口 再说一下代理服务器 先说明一下,我这个代理服务器只能代理指定的网站或其它可以代理的客户,比如建在内网的SVN服务或者有些地方不能访问的外网网站。 代理服务器分为服务器端和客户端,服务器端需要运行在客户端和大家都能访问的外网上,客户端需要放在能访问到需要代理的客户的网络上,也可以放在客户的本机上。 用法: 解压proxy.tar.gz 进入proxy目录,然后make,会生成三个我们需要的程序,transmit(转发服务器)、manager(代理服务器端)、client(代理客户端) 服务器端用法: ./transmit [端口](比如80) ./manager [端口](随便指定) 客户端用法: ./client -i [代理服务器IP]:[端口] -t [客户IP]:[端口] -d [客户域名] 举例: 假如我的外网服务器IP为1.2.3.4,代理的客户为网易(网易域名:www.163.com,IP:202.108.9.33) 服务器端如下运行 ./transmit 80 ./mananger 8000 客户端如下运行 ./client -i 1.2.3.4:8000 -t 202.108.9.33 -d www.163.com 或 ./client -i 1.2.3.4:8000 -t 202.108.9.33:80 -d www.163.com 然后在本机hosts文件(windows是c:windowssystem32driversetchosts linux是/etc/hosts)填加如下一行 1.2.3.4 www.163.com 这时在浏览器里敲www.163.com就可以通过代理服务器访问网易了 当然如果客户是自己申请域名,就可以直接把自己的域名指向1.2.3.4,而不用修改本机hosts文件了

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值