Menu Close

V2Ray+WebSocket+TLS+Nginx配置与使用教程

今年墙又升级了,很多SS/SSR用户的VPS IP都被封了,要么就是VPS的端口被秒封,本文介绍下V2ray使用WebSocket+TLS+Nginx来实现科学上网的方法,虽然配置比较麻烦,但是稳定性好,不容易被干扰,也不容易被墙。总是受VPS IP被墙这个问题困恼的朋友可以试试。

一、准备工作

首先要有一台国外VPS,这里推荐使用搬瓦工,年付$49.99起,还有CN2 GIA-E(年付$119起),支持支付宝,详细可以参考一些便宜性价比高的VPS推荐(搬瓦工VPS)。

之后需要一个域名,可以付费购买(推荐Namesilo),也可以在Freenom申请一个免费域名(申请教程),之后解析到你的VPS IP上。

二、安装V2Ray

直接使用V2Ray官方脚本即可:

  1. # 安装v2ray
  2. bash <(curl -L -s https://install.direct/go.sh) # 直接使用脚本
  3. service v2ray start # 启动
  4. vim /etc/v2ray/config.json # 修改配置文件

三、配置V2Ray服务器端

此脚本会自动安装以下文件:

  • /usr/bin/v2ray/v2ray:V2Ray 程序;
  • /usr/bin/v2ray/v2ctl:V2Ray 工具;
  • /etc/v2ray/config.json:配置文件;
  • /usr/bin/v2ray/geoip.dat:IP 数据文件
  • /usr/bin/v2ray/geosite.dat:域名数据文件 此脚本会配置自动运行脚本。自动运行脚本会在系统重启之后,自动运行 V2Ray。目前自动运行脚本只支持带有 Systemd 的系统,以及 Debian / Ubuntu 全系列。

运行脚本位于系统的以下位置:

  • /etc/systemd/system/v2ray.service: Systemd
  • /etc/init.d/v2ray: SysV
    脚本运行完成后,你需要:

编辑 /etc/v2ray/config.json 文件来配置你需要的代理方式;

运行 service v2ray start 来启动 V2Ray 进程;

之后可以使用 service v2ray start|stop|status|reload|restart|force-reload 控制 V2Ray 的运行。

编辑V2ray配置文件:

  1. {
  2. “log” : {
  3. “access”: “/var/log/v2ray/access.log”,
  4. “error”: “/var/log/v2ray/error.log”,
  5. “loglevel”: “warning”
  6. },
  7. “inbound”: {
  8. “port”: 9000, //(此端口与nginx配置相关)
  9. “listen”: “127.0.0.1”,
  10. “protocol”: “vmess”,
  11. “settings”: {
  12. “clients”: [
  13. {
  14. “id”: “eb950add-608e-409d-937f-e797324387093z”, //你的UUID, 此ID需与客户端保持一致
  15. “level”: 1,
  16. “alterId”: 64 //此ID也需与客户端保持一致
  17. }
  18. ]
  19. },
  20. “streamSettings”:{
  21. “network”: “ws”,
  22. “wsSettings”: {
  23. “path”: “/v2ray” //与nginx配置相关
  24. }
  25. }
  26. },
  27. “outbound”: {
  28. “protocol”: “freedom”,
  29. “settings”: {}
  30. },
  31. “outboundDetour”: [
  32. {
  33. “protocol”: “blackhole”,
  34. “settings”: {},
  35. “tag”: “blocked”
  36. }
  37. ],
  38. “routing”: {
  39. “strategy”: “rules”,
  40. “settings”: {
  41. “rules”: [
  42. {
  43. “type”: “field”,
  44. “ip”: [
  45. “0.0.0.0/8”,
  46. “10.0.0.0/8”,
  47. “100.64.0.0/10”,
  48. “127.0.0.0/8”,
  49. “169.254.0.0/16”,
  50. “172.16.0.0/12”,
  51. “192.0.0.0/24”,
  52. “192.0.2.0/24”,
  53. “192.168.0.0/16”,
  54. “198.18.0.0/15”,
  55. “198.51.100.0/24”,
  56. “203.0.113.0/24”,
  57. “::1/128”,
  58. “fc00::/7”,
  59. “fe80::/10”
  60. ],
  61. “outboundTag”: “blocked”
  62. }
  63. ]
  64. }
  65. }
  66. }

四、配置Nginx

Nginx安装很简单的,Google一下就有了。

另外,编辑Nginx配置文件,添加一个配置:

  1. server {
  2. # SSL configuration
  3. listen 443 ssl http2 default_server;
  4. listen [::]:443 ssl http2 default_server;
  5. ssl_certificate /ssl.pem; #你的ssl证书, 如果第一次,可能还需要自签一下,
  6. ssl_certificate_key /ssl.key; #你的ssl key
  7. root /var/www/html;
  8. # Add index.php to the list if you are using PHP
  9. index index.html index.htm index.nginx-debian.html;
  10. server_name test.v2ray.com; #你的服务器域名
  11. location /ray { #/ray 路径需要和v2ray服务器端,客户端保持一致
  12. proxy_redirect off;
  13. proxy_pass http://127.0.0.1:10000; #此IP地址和端口需要和v2ray服务器保持一致,
  14. proxy_http_version 1.1;
  15. proxy_set_header Upgrade $http_upgrade;
  16. proxy_set_header Connection “upgrade”;
  17. proxy_set_header Host $http_host;
  18. }
  19. }

关于域名ssl 证书,使用certbot自动签一个let’s encrypt证书就行了, 很简单,参考链接: https://certbot.eff.org/,成功后, 在crontab 中添加一条任务计划每三个月执行一次,因为let’s encrypt证书三个月过期:

  1. 0 0 15 */3 * /root/certbot/certbot-auto renew #在3,6,9,12月份的15号零点零分执行更新

五、配置V2Ray客户端

编辑V2Ray客户端配置文件:

  1. {
  2. “log”: {
  3. “loglevel”: “warning”
  4. },
  5. “inbound”: {
  6. “port”: 1080,
  7. “listen”: “127.0.0.1”,
  8. “protocol”: “socks”,
  9. “settings”: {
  10. “auth”: “noauth”,
  11. “udp”: false
  12. }
  13. },
  14. “inboundDetour”: [
  15. {
  16. “port”: 8123,
  17. “listen”: “127.0.0.1”,
  18. “protocol”: “http”,
  19. “settings”: {}
  20. }
  21. ],
  22. “outbound”: {
  23. “protocol”: “vmess”,
  24. “settings”: {
  25. “vnext”: [{
  26. “address”: “test.v2ray.com”, // 服务器地址,请修改为你自己的服务器 ip 或域名
  27. “port”: 443, // 服务器端口
  28. “users”: [{
  29. “id”: “461aad1f-687c-4188-9abc-80073a618ca3”, //你的UUID, 此ID需与服务端保持一致
  30. “level”: 1,
  31. “alterId”: 64, //此ID也需与客户端保持一致
  32. “security”: “aes-128-gcm”
  33. }]
  34. }]
  35. },
  36. “streamSettings”:{
  37. “network”: “ws”,
  38. “security”: “tls”,
  39. “tlsSettings”: {
  40. “serverName”: “test.v2ray.com” //此域名是你服务器的域名
  41. },
  42. “wsSettings”: {
  43. “path”: “/ray” //与服务器配置及nginx配置相关
  44. }
  45. },
  46. “tag”: “forgin”
  47. },
  48. “outboundDetour”: [
  49. {
  50. “protocol”: “freedom”,
  51. “settings”: {},
  52. “tag”: “direct”
  53. }
  54. ],
  55. “routing”: { //此路由配置是自动分流, 国内IP和网站直连
  56. “strategy”: “rules”,
  57. “settings”: {
  58. “domainStrategy”: “IPIfNonMatch”,
  59. “rules”: [
  60. {
  61. “type”: “chinaip”,
  62. “outboundTag”: “direct”
  63. },
  64. {
  65. “type”: “chinasites”,
  66. “outboundTag”: “direct”
  67. },
  68. {
  69. “type”: “field”,
  70. “ip”: [
  71. “0.0.0.0/8”,
  72. “10.0.0.0/8”,
  73. “100.64.0.0/10”,
  74. “127.0.0.0/8”,
  75. “169.254.0.0/16”,
  76. “172.16.0.0/12”,
  77. “192.0.0.0/24”,
  78. “192.0.2.0/24”,
  79. “192.168.0.0/16”,
  80. “198.18.0.0/15”,
  81. “198.51.100.0/24”,
  82. “203.0.113.0/24”,
  83. “::1/128”,
  84. “fc00::/7”,
  85. “fe80::/10”
  86. ],
  87. “outboundTag”: “direct”
  88. }
  89. ]
  90. }
  91. },
  92. “policy”: {
  93. “levels”: {
  94. “0”: {“uplinkOnly”: 0}
  95. }
  96. }
  97. }

或者下载Windows客户端:V2RayN

打开软件,点击:服务器→添加[VMess]服务器:

"/
填上你设置的对应数据,如服务器ip、端口、UUID(服务端和客户端必须一致),加密方式一般为aes-128-gcm,协议为ws,伪装域名留空,路径为/ray,开启tls和不安全传输,设置完保存。

右键V2RayN的系统栏小图标,点击启用Http代理,Http代理模式选择第二个PAC模式,最后再打开V2RayN软件面板,在检查更新里选择更新PAC。

到此,V2Ray就全部配置完成了。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注