写这篇文章同样只是满足我以后查资料的需要,主要目的并不是为了做教程,因为已经有人做得比我好太多太多,而且也很详尽。

步骤如下

0 准备工作

  • VPS就绪
  • 域名就绪
  • DNS服务器设置为Cloudflare
  • 域名已经解析到VPS的IP

1 安装宝塔面板

在putty中运行以下命令

CentOS

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh

Debian/ Ubuntu

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh
wget -O install.sh http://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh

2 安装Nginx

用宝塔面板即可安装

3 新建网站

4 部署ssl

可以用宝塔里面的一键申请,但如果使用了cdn的话不可以用宝塔申请。

我使用的是cloudflare的免费ssl。

在cloudflare后台的Crypto中申请安装。

5 设置Nginx

在网站配置文件的最后一行加上

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
location /ray{ #这个路径随便怎么设置
proxy_redirect off;
proxy_pass http://127.0.0.1:419; #这个端口随便怎么设置,但是要在防火墙中放行
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
location /ray{ #这个路径随便怎么设置 proxy_redirect off; proxy_pass http://127.0.0.1:419; #这个端口随便怎么设置,但是要在防火墙中放行 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $http_host; }
location /ray{                            #这个路径随便怎么设置
   proxy_redirect off;
   proxy_pass http://127.0.0.1:419;       #这个端口随便怎么设置,但是要在防火墙中放行
   proxy_http_version 1.1;
   proxy_set_header Upgrade $http_upgrade;
   proxy_set_header Connection "upgrade";
   proxy_set_header Host $http_host;
}

6 安装V2Ray

在putty中运行:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
wget https://install.direct/go.sh<br>bash go.sh<br>
wget https://install.direct/go.sh<br>bash go.sh<br>
wget https://install.direct/go.sh<br>bash go.sh<br>

安装完成后会得到端口和uuid,但这些都可以改。

在宝塔的文件管理中定位到 /etc/v2ray,编辑config.json来修改配置。

删除原来的内容,替换为以下内容:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
{
"inbounds": [
{
"port": 419, #之前在Nginx中设置的端口
"listen":"127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "******************", #刚刚得到的uuid,也可以自行生成一个uuid(可用PC版v2ray生成)
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/ray" #刚刚设置的路径
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
{ "inbounds": [ { "port": 419, #之前在Nginx中设置的端口 "listen":"127.0.0.1", "protocol": "vmess", "settings": { "clients": [ { "id": "******************", #刚刚得到的uuid,也可以自行生成一个uuid(可用PC版v2ray生成) "alterId": 64 } ] }, "streamSettings": { "network": "ws", "wsSettings": { "path": "/ray" #刚刚设置的路径 } } } ], "outbounds": [ { "protocol": "freedom", "settings": {} } ] }
{
  "inbounds": [
    {
      "port": 419,			    #之前在Nginx中设置的端口
      "listen":"127.0.0.1",
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "******************",     #刚刚得到的uuid,也可以自行生成一个uuid(可用PC版v2ray生成)
            "alterId": 64
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
        "path": "/ray"		            #刚刚设置的路径
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    }
  ]
}

记得手动启动一下v2ray

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
systemctl start v2ray
systemctl start v2ray
systemctl start v2ray

7 在客户端中使用

  • 地址为你的域名;
  • 端口为443;
  • Uuid为刚刚设置的uuid;
  • 协议为Websocket(ws);
  • 路径为 /ray(或者你设置的路径);
  • 开启tls。

8 参考原文地址

https://toutyrater.github.io/advanced/wss_and_web.html

https://www.igfw.net/archives/13463