Pages

Thursday, 26 September 2019

一个简单的http代理服务器程序:go-https-proxy

先在本地机器上,访问https://github.com/crabkun/go-https-proxy,fork该项目,我把它fork为了https://github.com/luckypoem/go-https-proxy ,编辑main.go文件-
https://github.com/luckypoem/go-https-proxy/edit/master/main.go,
把代码里面的
net.Listen("tcp",":8080")
改为
net.Listen("tcp","127.0.0.1:9070")

你若要改端口,也需先fork该项目,然后编辑
https://github.com/你的用户名/go-https-proxy/edit/master/main.go

登陆linux vps.首先安装go环境。然后,
cd $GOPATH
go get -u -v github.com/luckypoem/go-https-proxy
(可执行文件go-https-proxy就会出现在$GOPATH/bin/里面)

[root@host ~]# go-https-proxy
显示:
2019/09/26 21:31:23 listen at 127.0.0.1:9070

go-https-proxy是运行在前台的,容易退出。我们可以利用systemd来把此命令运行为service:
nano go-https-proxy.service
其内容为:
[Unit]
After=network.target

[Service]
ExecStart=/root/go/gopath/bin/go-https-proxy
Restart=always

[Install]
WantedBy=multi-user.target

然后,

systemctl start go-https-proxy
systemctl enable go-https-proxy
服务器端搭建完成。

这个http代理服务器程序可用作各种tunnel程序的后端。

https://github.com/crabkun/go-https-proxy/issues/1

类似的项目:
https://briteming.blogspot.com/2019/08/httphttp-proxy.html
https://briteming.blogspot.com/2019/07/gohttphttp-proxy.html (这个程序不需要改main.go文件,可在命令中,直接指定要监听的地址和端口)

No comments:

Post a Comment