Linux下使用V2ray客户端,使用privox转发socks到http,以及PAC配置
By - C灵C
首先下载脚本:
wget https://install.direct/go.sh
bash <(curl -L -s https://install.direct/go.sh)
然后执行脚本安装 V2Ray:
sudo bash go.sh
使用以下命令启动 V2Ray:
sudo systemctl start v2ray
其他命令:
status stop restart v2ray
在安装完 V2Ray 之后,修改配置文件 /etc/v2ray/config.json
此处建议拷贝其他客户端的config.json用来替换即可。
{
"log": {
"access": "",
"error": "",
"loglevel": "warning"
},
"inbounds": [
{
"port": 1080,
"listen": "127.0.0.1",
"protocol": "socks",
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
},
"settings": {
"auth": "noauth",
"udp": true,
"ip": null,
"clients": null
},
"streamSettings": null
}
],
"outbounds": [
{
"tag": "proxy",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "45.77.26.33",
"port": 10086,
"users": [
{
"id": "6ba33488-a20d-46b6-a315-4fcbecbfeb44",
"alterId": 243,
"email": "t@t.tt",
"security": "auto"
}
]
}
],
"servers": null,
"response": null
},
"streamSettings": {
"network": "tcp",
"security": "",
"tlsSettings": null,
"tcpSettings": null,
"kcpSettings": null,
"wsSettings": null,
"httpSettings": null,
"quicSettings": null
},
"mux": {
"enabled": true
}
},
{
"tag": "direct",
"protocol": "freedom",
"settings": {
"vnext": null,
"servers": null,
"response": null
},
"streamSettings": null,
"mux": null
},
{
"tag": "block",
"protocol": "blackhole",
"settings": {
"vnext": null,
"servers": null,
"response": {
"type": "http"
}
},
"streamSettings": null,
"mux": null
}
],
"dns": null,
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": []
}
}
更新 V2Ray 的方法是再次执行安装脚本。
shadowsocks,v2ray 都是将代理转为本地 socks5 代理,
所以如果需要使用 http 代理,就需要借助 Privoxy 。
sudo apt install privoxy
默认的配置文件地址在 /etc/privoxy/config 目录下。
假设本地 1080 端口已经启动(不管是本地 sslocal 还是 v2ray 本地都需要启动)然后要将本地 1080 socks5 代理转成 http 代理,重要的配置只有两行。
# 把本地 HTTP 流量转发到本地 1080 SOCKS5 代理
forward-socks5t / 127.0.0.1:1080 .
# 默认添加,监听本地连接
listen-address 127.0.0.1:8118
修改完成保存之后使用如下命令启动。
sudo /etc/init.d/privoxy start
# 不重启服务的情况下重新加载配置
sudo /etc/init.d/privoxy reload
可以在终端进行测试
export http_proxy=http://127.0.0.1:8118 && curl ip.gs 应该显示代理的 IP 地址。
如果监听 0.0.0.0:8118 ,那么局域网中,使用 ip:8118 也能够使用该 HTTP 代理,并且所有的流量都经由 HTTP 转发到 SOCKS5 代理,并走 shadowsocks 或者 v2ray 到墙外。
我们配置了网络代理后会发现它是全局的 当我们访问国内网站他还是会去走代理,反而影响了国内网站的访问速度。而且还有出现一些bug例如host修改失效,这种时候就需要用到PAC它会帮我们检测分辨网站是国内还是国外是否通过代理来访问。
我们通过GenPAC来生成pac文件
# 安装
pip install genpac
# 从gfwlist生成代理信息为SOCKS5 127.0.0.1:1080的PAC文件
genpac --format=pac --pac-proxy="SOCKS5 127.0.0.1:1080" -o /etc/v2ray/autoproxy.pac
文章评论