來源:逗比根據地
原文: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官方腳本即可:
- # 安裝v2ray
- bash <(curl –L –s https://install.direct/go.sh) # 直接使用腳本
- service v2ray start # 啟動
- 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配置文件:
- {
- “log” : {
- “access”: “/var/log/v2ray/access.log”,
- “error”: “/var/log/v2ray/error.log”,
- “loglevel”: “warning”
- },
- “inbound”: {
- “port”: 9000, //(此埠與nginx配置相關)
- “listen”: “127.0.0.1”,
- “protocol”: “vmess”,
- “settings”: {
- “clients”: [
- {
- “id”: “eb950add-608e-409d-937f-e797324387093z”, //你的UUID, 此ID需與客戶端保持一致
- “level”: 1,
- “alterId”: 64 //此ID也需與客戶端保持一致
- }
- ]
- },
- “streamSettings”:{
- “network”: “ws”,
- “wsSettings”: {
- “path”: “/v2ray” //與nginx配置相關
- }
- }
- },
- “outbound”: {
- “protocol”: “freedom”,
- “settings”: {}
- },
- “outboundDetour”: [
- {
- “protocol”: “blackhole”,
- “settings”: {},
- “tag”: “blocked”
- }
- ],
- “routing”: {
- “strategy”: “rules”,
- “settings”: {
- “rules”: [
- {
- “type”: “field”,
- “ip”: [
- “0.0.0.0/8”,
- “10.0.0.0/8”,
- “100.64.0.0/10”,
- “127.0.0.0/8”,
- “169.254.0.0/16”,
- “172.16.0.0/12”,
- “192.0.0.0/24”,
- “192.0.2.0/24”,
- “192.168.0.0/16”,
- “198.18.0.0/15”,
- “198.51.100.0/24”,
- “203.0.113.0/24”,
- “::1/128”,
- “fc00::/7”,
- “fe80::/10”
- ],
- “outboundTag”: “blocked”
- }
- ]
- }
- }
- }
四、配置Nginx
Nginx安裝很簡單的,Google一下就有了。
另外,編輯Nginx配置文件,添加一個配置:
- server {
- # SSL configuration
- listen 443 ssl http2 default_server;
- listen [::]:443 ssl http2 default_server;
- ssl_certificate /ssl.pem; #你的ssl證書, 如果第一次,可能還需要自簽一下,
- ssl_certificate_key /ssl.key; #你的ssl key
- root /var/www/html;
- # Add index.php to the list if you are using PHP
- index index.html index.htm index.nginx–debian.html;
- server_name test.v2ray.com; #你的伺服器域名
- location /ray { #/ray 路徑需要和v2ray伺服器端,客戶端保持一致
- proxy_redirect off;
- proxy_pass http://127.0.0.1:10000; #此IP地址和埠需要和v2ray伺服器保持一致,
- proxy_http_version 1.1;
- proxy_set_header Upgrade $http_upgrade;
- proxy_set_header Connection “upgrade”;
- proxy_set_header Host $http_host;
- }
- }
關於域名ssl 證書,使用certbot自動簽一個let』s encrypt證書就行了, 很簡單,參考鏈接: https://certbot.eff.org/,成功後, 在crontab 中添加一條任務計劃每三個月執行一次,因為let』s encrypt證書三個月過期:
- 0 0 15 */3 * /root/certbot/certbot–auto renew #在3,6,9,12月份的15號零點零分執行更新
五、配置V2Ray客戶端
編輯V2Ray客戶端配置文件:
- {
- “log”: {
- “loglevel”: “warning”
- },
- “inbound”: {
- “port”: 1080,
- “listen”: “127.0.0.1”,
- “protocol”: “socks”,
- “settings”: {
- “auth”: “noauth”,
- “udp”: false
- }
- },
- “inboundDetour”: [
- {
- “port”: 8123,
- “listen”: “127.0.0.1”,
- “protocol”: “http”,
- “settings”: {}
- }
- ],
- “outbound”: {
- “protocol”: “vmess”,
- “settings”: {
- “vnext”: [{
- “address”: “test.v2ray.com”, // 伺服器地址,請修改為你自己的伺服器 ip 或域名
- “port”: 443, // 伺服器埠
- “users”: [{
- “id”: “461aad1f-687c-4188-9abc-80073a618ca3”, //你的UUID, 此ID需與服務端保持一致
- “level”: 1,
- “alterId”: 64, //此ID也需與客戶端保持一致
- “security”: “aes-128-gcm”
- }]
- }]
- },
- “streamSettings”:{
- “network”: “ws”,
- “security”: “tls”,
- “tlsSettings”: {
- “serverName”: “test.v2ray.com” //此域名是你伺服器的域名
- },
- “wsSettings”: {
- “path”: “/ray” //與伺服器配置及nginx配置相關
- }
- },
- “tag”: “forgin”
- },
- “outboundDetour”: [
- {
- “protocol”: “freedom”,
- “settings”: {},
- “tag”: “direct”
- }
- ],
- “routing”: { //此路由配置是自動分流, 國內IP和網站直連
- “strategy”: “rules”,
- “settings”: {
- “domainStrategy”: “IPIfNonMatch”,
- “rules”: [
- {
- “type”: “chinaip”,
- “outboundTag”: “direct”
- },
- {
- “type”: “chinasites”,
- “outboundTag”: “direct”
- },
- {
- “type”: “field”,
- “ip”: [
- “0.0.0.0/8”,
- “10.0.0.0/8”,
- “100.64.0.0/10”,
- “127.0.0.0/8”,
- “169.254.0.0/16”,
- “172.16.0.0/12”,
- “192.0.0.0/24”,
- “192.0.2.0/24”,
- “192.168.0.0/16”,
- “198.18.0.0/15”,
- “198.51.100.0/24”,
- “203.0.113.0/24”,
- “::1/128”,
- “fc00::/7”,
- “fe80::/10”
- ],
- “outboundTag”: “direct”
- }
- ]
- }
- },
- “policy”: {
- “levels”: {
- “0”: {“uplinkOnly”: 0}
- }
- }
- }
或者下載Windows客戶端:V2RayN
打開軟體,點擊:伺服器→添加[VMess]伺服器:
填上你設置的對應數據,如伺服器ip、埠、UUID(服務端和客戶端必須一致),加密方式一般為aes-128-gcm
,協議為ws
,偽裝域名留空,路徑為/ray
,開啟tls和不安全傳輸,設置完保存。
右鍵V2RayN的系統欄小圖標,點擊啟用Http代理
,Http代理模式選擇第二個PAC模式
,最後再打開V2RayN軟體面板,在檢查更新里選擇更新PAC
。
到此,V2Ray就全部配置完成了。
轉載請超鏈接註明:逗比根據地 » V2Ray+WebSocket+TLS+Nginx配置與使用教程