tinyproxy代理配置

有时候处于内网的服务器不能直接访问外网,这对下载数据和conda以及github上的软件包带来了很大困扰。此时如果有一台内网服务器可以访问的服务器,而这台服务器又可以访问外网的话,我们就可以通过tinyproxy把这台服务器当作代理服务器,让内网服务器通过代理服务器间接访问外网。

ubuntu安装

1
sudo apt-get install tinyproxy

配置:/etc/tinyproxy.conf

1
2
3
4
5
6
7
8
9
10
11
12
# 如果/var/log/tinyproxy/tinyproxy.log权限报错,就把下面两行改成/var/log/tinyproxy的所有者
User tinyproxy
Group tinyproxy

# 设置端口
Port 3216

# 可以设置用户名和密码
BasicAuth user passwd

# 可以设置连接的IP地址限制
Allow ip

启动

1
2
# -d debug模式,取消-d进入后台运行
$ sudo tinyproxy -d -c /etc/tinyproxy.conf

查看进程

1
2
3
4
5
$ ps -ef|grep tinyproxy|grep -v grep
tinypro+ 690507 1 0 20:24 ? 00:00:00 /usr/bin/tinyproxy
root 691964 690216 0 20:29 pts/6 00:00:00 sudo tinyproxy -d -c /etc/tinyproxy.conf
root 691965 691964 0 20:29 pts/7 00:00:00 sudo tinyproxy -d -c /etc/tinyproxy.conf
root 691966 691965 0 20:29 pts/7 00:00:02 tinyproxy -d -c /etc/tinyproxy.conf

终止

1
$ sudo ps -ef|grep tinyproxy|grep -v grep|awk '{print "kill -9 "$2}'|sudo sh

配置代理

在.zshrc(bash 就是.bashrc)中加入:

1
2
3
4
5
6
7
export http_proxy="http://ip:port"
export https_proxy="http://ip:port"

# 有用户名密码验证的话
export http_proxy="http://user:passwd@ip:port"
export https_proxy="http://user:passwd@ip:port"

conda不需要额外在.condarc中配置代理。

git代理配置

1
2
3
4
5
6
7
# git设置代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy http://127.0.0.1:1080

# git取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy

github ssh协议要走ssh隧道,编辑~/.ssh/config

1
2
3
Host github.com
HostName github.com
ProxyCommand ssh hongxi@115.24.151.249 -W %h:%p

tinyproxy代理配置
http://example.com/2022/10/03/tinyproxy代理配置/
作者
Wang Jianhua
发布于
2022年10月3日
许可协议