7

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

 3 years ago
source link: https://xtrojan.org/bgfw/v2ray/v2ray-websocket-tls-nginx-config.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

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

四、配置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;

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

或者下载Windows客户端:V2RayN

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


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

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

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


Recommend

  • 84
    • www.williamlong.info 5 years ago
    • Cache

    V2Ray安装使用教程

    V2Ray安装使用教程 2019-6-3 21:26:23 | 作者: 月光 | 分类:

  • 7
    • xugaoxiang.com 3 years ago
    • Cache

    v2ray的安装配置及使用

    软硬件环境 ubuntu server 18.04 64bit v2rayN for windows bandwagon vps 什么是v2ray

  • 14

    2021 VPS 配置 v2ray + WebSocket + TLS 梯子教程 Clloz · 2天前 ·

  • 7
    • blog.leixin.wang 3 years ago
    • Cache

    配置v2ray+nginx+ws访问国际网络

    配置v2ray+nginx+ws访问国际网络 发表于...

  • 9

    下文以nginx为例,介绍如何部署一个高性能,高安全性的https服务器。 并附送一个优化出来的openssl编译脚本,可以编译出一个高性能,高安全性的openssl库,您可以直接复制粘贴使用。 此处直接给出实践指导,后续再写文章解释tls协议的这些原理细...

  • 18
    • www.jansora.com 3 years ago
    • Cache

    v2Ray Linux下无GUI配置教程

    安装(服务端和客户端都适用) 1.下载安装脚本 wget https://install.direct/go.sh https://install.direct/go.sh 2.1 在线安装脚本 需要连接 gi...

  • 28

    一键脚本安装V2Ray+WebSocket+TLS+Nginx救活被墙VPS 之前介绍了手动配置V2Ray+WebSocket+TLS+Nginx的教程(V2Ray+WebSocket+TLS+Nginx配置与使用教程),配置比较繁琐,这里分享一个一键脚本实现V2Ray 基于 Nginx 的 vmess+ws+tls。

  • 32

    什么是v2rayN?v2rayN是一个V2Ray的Windows客户端,支持Xray内核和v2fly内核。最后一次更新于2022年5月6日。当前最新版本是v2rayN5.23。v2rayN是一款PC端比较受欢迎,且功能强大的代理软件。v2rayN下载点击下载:

  • 7

    使用Linux+Nginx+TLS+WS+CDN安装配置V2rayV2ray安装配置很简单,跟着下面一步一步搭建安全快速的V2Ray服务端,Nginx+TLS+WS(WebSocket)+CDN简单又安全!在日常网络生活中,隐私泄露的危险无处不在,如何保护你的个人隐私提高你在互联网上的用户安全性?

  • 10

    首页技术宅v2rayN 6.x 使用教程 V2Ray 的 Windows 客户端v2rayN 6.x 使用教程 V2Ray 的 Windows 客户端...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK