最近ChatGPT很火,由于国内很难使用到,所以我便用其API做了一个小助手,但是没想到这个API也需要翻墙,而我的服务器又是腾讯云的,国内服务器根本无法访问到国外网站,所以便想到给服务器加代理的方式,实现服务器可以访问外网。
1.下载安装包
从 https://github.com/v2ray/v2ray-core/releases/tag/v4.31.0 下载 v2ray-linux-64.zip 文件并解压(实际上选择合适自己机器的就行了 这里选用的是最小包 解压即用)
2.配置config.json文件
因为我们的v2ray此时是用来作为客户端工作,所以需要配置节点节点的配置文件为 config.json。节点文件可以从v2ray的Windows客户端导出。前提是我们在Windows客户端使用的v2ray已经有服务器节点可用。
在linux上运行v2ray
cd v2ray-linux-64/
chmod +x v2ray v2ctl
vim config.json
把上边导出的配置内容复制到config.json中
{
"log": {
"loglevel": "info"
},
"inbounds": [
{
"port": 1080,
"protocol": "socks",
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
},
"settings": {
"udp": true // 开启 UDP 协议支持
}
},
{
"port": 10809,
"protocol": "http",
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
}
}
],
"outbounds": [
{
"tag": "proxy-vmess",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "nas.inat.top", // 服务器的 IP
"port": 53689, // 服务器的端口
"users": [
{
// id 就是 UUID,相当于用户密码
"id": "77ba2a7d-3e1d-486c-a2f5-c8718d3d1560",
"alterId": 10
}
]
}
]
}
},
{
"tag": "direct",
"settings": {},
"protocol": "freedom"
}
],
"dns": {
"server": [
"8.8.8.8",
"1.1.1.1"
],
// 你的 IP 地址,用于 DNS 解析离你最快的 CDN
"clientIp": "202.113.37.69"
},
// 配置路由功能
"routing": {
"domainStrategy": "IPOnDemand",
"rules": [
{
"type": "field",
"domain": [
"cnblogs.com"
],
"outboundTag": "proxy-vmess"
},
{
"type": "field",
"domain": [
"domain:inat.top"
],
"outboundTag": "direct"
}
]
}
}
下面操作就是更便捷的为Linux下的v2ray客户端配置服务器节点
[root@VM-8-11-centos v2]# ./v2ray -test config.json
V2Ray 4.44.0 (V2Fly, a community-driven edition of V2Ray.) Custom (go1.17.3 linux/amd64)
A unified platform for anti-censorship.
2022/02/23 22:23:52 [Info] main/jsonem: Reading config: config.json
Configuration OK.
[root@VM-8-11-centos v2]#
3.运行
如果没有安装screen 就先安装screen ,yum install screen ,然后执行以下命令
screen -S v2ray
./v2ray config.json
4.测试
curl -x http://127.0.0.1:10809 www.google.com
其中的 10809 端口为我们配置文件中配置的端口,每个人的可能都不相同。
到这个地方就可以了。下边不用看
5.设置全局代理
修改文件“/etc/profile”,在文件结束位置增加如下内容(按你config.json里配):
# 设置http代理
export http_proxy=socks5://127.0.0.1:10808
# 设置https代理
export https_proxy=socks5://127.0.0.1:10808
修改后重启服务器,上面的设置才会生效。或者不重启服务器,执行以下命令使配置立即生效
source /etc/profile
如果要取消代理,需要执行以下命令:
unset http_proxy
unset https_proxy
最后,你就会发现你可以正常使用外网服务啦!
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容