首先,你需要准备一个域名添加A记录解析到你的VPS IP,可以去购买一个便宜的域名,然后用cloudflare把IP地址隐藏(但在弄好v2ray之前最好先不要隐藏IP)。

下面是详细步骤(用Xshell登录SSH服务器):

安装V2Ray

这里使用的是centos7系统
bash <(curl -L -s https://install.direct/go.sh)

安装SSL证书

安装EPEL:yum -y install epel-release
安装certbot用于签发SSL证书: yum -y install certbot
申请SSL证书:certbot certonly --standalone -d example.com
这里的example.com替换成你的域名,至于为什么要申请SSL证书呢,是因为如果没有证书,浏览器会认为你的访问是不安全的从而被阻止访问。

申请证书会要求填入一个邮箱地址或者输入C回车取消申请(输入错了可以按CTRL+删除键),然后输入A同意或者C取消。

如果申请成功,证书和私钥路径如下:
/etc/letsencrypt/live/example.com/fullchain.pem
/etc/letsencrypt/live/example.com/privkey.pem

Your cert will expire on 2020-06-15. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"

您的证书将在2020-xx-xx到期。要在将来获得此证书的新版本或调整过的版本,只需再次运行certbot。要非交互式地更新所有*证书,请运行“ certbot renew”(三个月后)

注意:如果是提示Problem binding to port 80: Could not bind to IPv4 or IPv6. 可能是nginx占用了80端口,输入 service nginx stop 先停止服务。

至此,V2ray安装完成,接下来安装nginx(也就是配置网站),当然,如果你的VPS已经安装了像宝塔BT的控制面板,可以省略下面安装nginx步骤,在宝塔面板中安装nginx(建议1.13版本以上),然后申请证书,并按下面的配置文件。

配置Nginx

添加一个Nginx安装源:vi /etc/yum.repos.d/nginx.repo
按 i 开启编辑模式,写入:

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

写入完按ESC,然后输入":wq",按回车保存退出。
安装Nginx:yum -y install nginx
新建一个Nginx站点配置文件:vi /etc/nginx/conf.d/v2ray.conf
写入:

server {
    listen       443 ssl;
    server_name  example.com;

    ssl_certificate    /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key    /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    error_page 497  https://$host$request_uri;

location /ray {
    proxy_pass       http://127.0.0.1:10000;
    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;
    }
}

注意:如果已经在宝塔面板中申请了证书,它会自动配置证书,所以只需要最下面location...那一段即可。
其中443是网站端口同时也是V2Ray传输端口,127.0.0.1:10000其中的10000是监听端口,可以自行更改,然后防火墙放行所需端口,或者直接关闭防火墙。

配置V2Ray服务端

备份一下v2ray的默认配置文件:cp /etc/v2ray/config.json /etc/v2ray/config.jsonbak
清空配置文件的内容:echo "" > /etc/v2ray/config.json
编辑配置文件:vi /etc/v2ray/config.json
写入:

{
  "inbounds": [
    {
      "port": 10000,
      "listen":"127.0.0.1",
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "你的UUID",
            "alterId": 64
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
        "path": "/ray"
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    }
  ]
}

vi打开文件后是命令模式状态,要用i或者a命令或Insert键才可进入可编辑的状态(最下面会出现INSERT字样)
要保存文件按esc,这样就会退回vi的命令模式,输入冒号(英文的),然后就转换到了末行模式,再输入wq回车保存文件,q则不保存。

注意:安装完v2ray会给出一个五位数的端口和UUID,你可以填入那个,也可以端口自己取,然后UUID用客户端生成,但记住要保持一致。

检查是否运行正常:

systemctl status v2ray
systemctl status nginx

返回如果有running字样代表正常,否则:
检测v2ray配置文件格式是否正确:
/usr/bin/v2ray/v2ray --test --config /etc/v2ray/config.json

重启两个服务让修改生效:
重启v2ray service v2ray restart
重启nginx service nginx restart

配置V2Ray客户端

下载V2RayN客户端(Windows): v2rayN
点击:服务器→添加[VMess]服务器
填上你设置的对应数据,如服务器ip、端口、UUID(服务端和客户端必须一致),加密方式一般为aes-128-gcm,协议为ws,
伪装域名留空,路径为/ray,开启tls和不安全传输,设置完保存
右键V2RayN的系统栏小图标,点击启用Http代理,Http代理模式选择第二个PAC模式
最后再打开V2RayN软件面板,在检查更新里选择更新PAC
到此,V2Ray就全部配置完成了。

注意:
V2Ray的客户端Core和服务端Core版本必须一致,请自行检查更新。
V2Ray对本地时间和服务端时间的要求较高,一般执行脚本后会自动校时,如出现连接失误,请检查服务器的时间。

修改centos系统时间

1、查看当前的系统时间:date
2、查看当前时区: timedatectl status
3、修改时间: date -s "2020-xx-xx 00:00:00"
4、修改时区: timedatectl set-timezone Asia/Shanghai
5、重启系统:reboot

本文转载