翻牆教程之V2Ray+WebSocket+TLS+Nginx配置與使用

來源:逗比根據地

原文:https://doubibackup.com/v2ray-ws-tls-nginx.html

今年牆又升級了,很多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.  
  8. root /var/www/html;
  9.  
  10. # Add index.php to the list if you are using PHP
  11. index index.html index.htm index.nginxdebian.html;
  12.  
  13. server_name test.v2ray.com; #你的伺服器域名
  14.  
  15. location /ray { #/ray 路徑需要和v2ray伺服器端,客戶端保持一致
  16. proxy_redirect off;
  17. proxy_pass http://127.0.0.1:10000; #此IP地址和埠需要和v2ray伺服器保持一致,
  18. proxy_http_version 1.1;
  19. proxy_set_header Upgrade $http_upgrade;
  20. proxy_set_header Connection “upgrade”;
  21. proxy_set_header Host $http_host;
  22. }
  23. }

關於域名ssl 證書,使用certbot自動簽一個let』s encrypt證書就行了, 很簡單,參考鏈接: https://certbot.eff.org/,成功後, 在crontab 中添加一條任務計劃每三個月執行一次,因為let』s encrypt證書三個月過期:

  1. 0 0 15 */3 * /root/certbot/certbotauto 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]伺服器:

v2rayN-1
填上你設置的對應數據,如伺服器ip、埠、UUID(服務端和客戶端必須一致),加密方式一般為aes-128-gcm,協議為ws,偽裝域名留空,路徑為/ray,開啟tls和不安全傳輸,設置完保存。

右鍵V2RayN的系統欄小圖標,點擊啟用Http代理,Http代理模式選擇第二個PAC模式,最後再打開V2RayN軟體面板,在檢查更新里選擇更新PAC

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

轉載請超鏈接註明:逗比根據地 » V2Ray+WebSocket+TLS+Nginx配置與使用教程