Linux下搭建TinyProxy代理服务器

作为一个在网上玩了很久的人,有的时候需要一些代理服务器,用来提高网络访问的速度。这勾起了我不少的回忆。在学生时代,大约是2000年前后,玩的都是局域网。虽然校内资源很多,但架不住外面互联网好玩,但是作为穷学生,我们在学生公寓上网还是比较贵的,电信网需要1块钱一个小时,那时候出口带宽很小,我记得才30M,而教育网是不对学生公寓开放的。所以那个时候,经常会在实验室的服务器上搭建代理服务器,免费上网的感觉真的很不错,而最初玩的也就是HTTP代理。离开学校,接触了更多的事,虽然HTTP代理服务器基本上是裸奔,也没什么太大的用处,但是在一些场景下还是需要用到的,这里记录一下Linux下一个简单轻量的代理服务器TinyProxy搭建过程。

下载源代码

TinyProxy代码托管在GitHub上,可以访问项目地址查看更多的信息

# 下载TinyProxy的最新版本,最新版本是1.11.2
wget https://github.com/tinyproxy/tinyproxy/releases/download/1.11.2/tinyproxy-1.11.2.tar.gz
# 解压缩文件
tar -xvpf tinyproxy-1.11.2.tar.gz
# 进入tinyproxy目录
cd tinyproxy-1.11.2
#  启动安装
./autogen.sh
./configure
make
make install

修改配置文件

接下来可以不管安装程序建立的配置文件,自己来建立tinyproxy的配置文件

#  建立配置文件夹
   mkdir /etc/tinyproxy/
#  编辑配置文件
   nano /etc/tinyproxy/tinyproxy.conf

将以下内容写入配置文件

User nobody
Group nobody
Port 3128
BindSame yes
Timeout 30
StatHost "127.0.0.1"
StatFile "/usr/local/share/tinyproxy/stats.html"
LogFile "/var/log/tinyproxy/tinyproxy.log" 
LogLevel Info
MaxClients 1024
ViaProxyName "baidu"
XTinyproxy no
DisableViaHeader yes
BasicAuth xxxx yyyy

这里有几个地方需要注意。一是UserGroup要修改,建议修改成为系统里存在的用户名,比如root:root,否则后期运行会出错。二是Port需要修改,默认是3128端口,可以修改成别的,默认的3128端口不安全。三是ViaProxyName需要修改,建议改成其他的东西,以免被扫描段口的时候刺探信息。最后,BasicAuth参数修改成你的用户名和密码,中间用空格隔开。

设置运行脚本

#建立启动文件
nano /usr/bin/tp

将如下代码写入文件

#!/bin/bash
if [ $# -lt 1 ]
then
    echo "No Args Input..."
    exit ;
fi
case $1 in
"start")
        echo " =================== 启动 ==================="
        nohup tinyproxy -d -c /etc/tinyproxy/tinyproxy.conf > /dev/null 2>&1 &
;;
"stop")
        echo " =================== 关闭 ==================="
        ps -ef|grep tinyproxy|grep -v grep|awk '{print "kill -9 "$2}'|sh
;;
"restart")
        echo " =================== 重启 ==================="
        ps -ef|grep tinyproxy|grep -v grep|awk '{print "kill -9 "$2}'|sh
        nohup tinyproxy -d -c /etc/tinyproxy/tinyproxy.conf > /dev/null 2>&1 &
;;
"status")
        echo " =================== 状态 ==================="
        ps -ef|grep tinyproxy|grep -v grep
;;
*)
    echo "Input Args Error..."
;;
esac

设置脚本权限

# 设置权限
 chmod 777 /usr/bin/tp

脚本的使用

# 启动tinyproxy
tp start
# 停止tinyproxy
tp stop
# 查看运行状态
tp status
# 重新启动
tp restart
# 另外的启动方式tinyproxy -c /etc/tinyproxy/tinyproxy.conf启动程序
#查看日志
tail -f /var/log/tinyproxy/tinyproxy.log
未经允许不得转载:南埜小站 » Linux下搭建TinyProxy代理服务器

相关文章

评论 (0)