小内存NAT VPS安装v2ray

上一次基于大内存VPS使用Docker安装的,但是在小内存的NAT VPS上强行安装Docker就会显得有点捉襟见肘了,所以我们可以直接使用脚本安装。
由于我使用的是Debian 10系统,并且由于之前已经使用Docker安装的老版本的v2ray,所以本次依然安装旧版本的v2ray,使用的是v4.22.1版本

v2ray

直接从上述版本的路径获取到安装脚本,需要注意的是, 如果安装指定版本的话,就需要手动修改脚本中的“CUR_VER”和“NEW_VER”字段,例如我就改为安装的“v4.22.1”。

然后执行安装命令就会自动安装:

bash install-release.sh

设置v2ray开机自启:

systemctl enable v2ray

安装完需要修改配置文件,由于我需要套用cloudflare来加速,所以我需要配置websocket,同时为了方便直连加速,我也配置了kcp加速。

编辑配置文件:

nano /etc/v2ray/config.json

config.json完整的配置文件如下:

{
    "inbounds": [{
        "port": 10000,
        "protocol": "vmess",
        "settings": {
            "clients": [{
                "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                "alterId": 64
            }]
        },
        "streamSettings": {
            "network": "mkcp",
            "kcpSettings": {
                "uplinkCapacity": 5,
                "downlinkCapacity": 100,
                "congestion": true,
                "header": {
                    "type": "none"
                }
            }
        }
    }, {
        "port": 20000,
        "protocol": "vmess",
        "settings": {
            "clients": [{
                "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
                "alterId": 64
            }]
        },
        "streamSettings": {
            "network": "ws",
            "wsSettings": {
                "path": "/somepath",
                "headers": {
                    "Host": "my.host.name"
                }
            }
        }
    }],
    "outbounds": [{
        "protocol": "freedom",
        "settings": {}
    }, {
        "protocol": "blackhole",
        "settings": {},
        "tag": "blocked"
    }],
    "routing": {
        "rules": [{
            "type": "field",
            "ip": ["geoip:private"],
            "outboundTag": "blocked"
        }]
    }
}

检查v2ray配置是否有误:

/usr/bin/v2ray/v2ray -config /etc/v2ray/config.json -test

没问题的话重启v2ray使新的配置生效:

systemctl restart v2ray

nginx

正如前面所有,由于我需要配置websocket,所以还需要额外配置nginx,配置nginx还需要搞定域名签名问题,我们可以使用 python-certbot-nginx 来自动进行签名。

安装nginx/certbot:

apt -y update 
apt -y install nginx python-certbot-nginx

新建nginx配置文件:

nano /etc/nginx/conf.d/v2ray.conf

v2ray.conf完整的配置文件如下:

server {
    listen       [::]:80;
    listen       [::]:443 ssl;
    server_name  my.host.name;

location /somepath {
    proxy_pass       http://127.0.0.1:20000;
    proxy_redirect             off;
    proxy_http_version         1.1;
    proxy_set_header Upgrade   $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host      $http_host;
    }
}

检查nginx配置是否有误:

nginx -t

使用certbot签发一个ssl证书:

certbot --nginx --agree-tos --no-eff-email --email [email protected]

certbot是一个非常方便的ssl证书申请工具,可以自动为nginx配置证书/自动续期,按照提示的步骤选择即可。

设置nginx开机自启:

systemctl enable nginx

同时附上我修改后的 install-release.sh

标签:v2ray