202205 nginx反代v2ray docker (vmess+tls)

date
May 3, 2022
slug
nginx-vmess-tls-v2ray-docker
status
Published
summary
小技巧 v2ray v2fly
tags
tip
type
Post
URL

Problem & Summary

    Solution

    服务器Docker

    export V2RAY_UUID=$(cat /proc/sys/kernel/random/uuid) 
    echo $V2RAY_UUID
    mkdir -p /data/v2ray
    cd /data/v2ray
    cat > config.json <<EOF
    {
      "log": {
        "loglevel": "debug", // error > warning > notice > info > debug
        "access": "/etc/v2ray/access.log", // 这是 Linux 的路径
        "error": "/etc/v2ray/error.log"
      },
      "inbounds": [{
        "port": 65432,           //此处为安装时生成的端口,可修改随意,但是保证和下面提到的端口号相同
        "listen":"0.0.0.0",
        "protocol": "vmess",
        "settings": {
          "clients": [
            {
              "id": "${V2RAY_UUID}", //此处为安装时生成的 id
              //"level": 1,
              "alterId": 0      //此处为安装时生成的 alterId
            }
          ]
        },
        "streamSettings": {
          "network": "ws",
          "wsSettings": {
            "path": "/SoftDown"   //此处为路径,需要和下面 NGINX 上面的路径配置一样
          }
        }
      }],
      "outbounds": [{
        "protocol": "freedom",
        "settings": {}
      }],
      "routing": {
        "rules": [
          {
            "type": "field",
            "ip": ["geoip:private"],
            "outboundTag": "direct"
          }
        ]
      }
    }
    EOF
    
    
    docker run -d \
      --name v2ray \
      --restart always \
      -p 65432:65432 \
      -e TZ=Asia/Shanghai \
      -v $(pwd):/etc/v2ray \
      v2fly/v2fly-core run -c /etc/v2ray/config.json
    
    sleep 1s; docker logs -f v2ray
    
    # 这个可以和cfwarp共存
    #   --net=host \
    # 可以换成
    # -p 65432:65432 \
    
    docker run -d \
      --name v2ray \
      --restart always \
      --net=host \
      -e TZ=Asia/Shanghai \
      -v $(pwd):/etc/v2ray \
      v2fly/v2fly-core run -c /etc/v2ray/config.json
    
    # or docker-compose.yml
    cat > docker-compose.yml <<EOF
    version: "3"
    services:
    v2ray:
        image: v2fly/v2fly-core
        container_name: v2ray
        #command: v2ray -config=/etc/v2ray/config.json
        # new version 20230213
        command: run -c /etc/v2ray/config.json
        ports:
          - 65432:65432
        restart: always
        environment:
            TZ: Asia/Shanghai
        volumes:
            - ./v2ray:/etc/v2ray
    networks:
      default:
        name: npm_nginx_proxy_manager-network
        external: true
    EOF
    
    docker-compose down; docker-compose up -d; sleep 1s; docker-compose logs -f

    宝塔网站配置文件中

    notion image
    location /SoftDown {
          proxy_redirect off;
          proxy_pass http://127.0.0.1:65432;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $http_host;
        }

    Clash客户端配置 - 替换xxx.xxx.xxx

    
    echo $V2RAY_UUID 
    export V2_DOMAIN=xxx.xxx.xxx
    cat <<EOF
    - name: "V2_$V2_DOMAIN"
      type: vmess
      server: $V2_DOMAIN
      port: 443
      uuid: $V2RAY_UUID
      alterId: 0
      cipher: auto
      # udp: true
      tls: true
      #tls-hostname: $V2_DOMAIN # for TLS SNI
      servername: $V2_DOMAIN # priority over wss host
      network: ws
      ws-opts:
        path: /SoftDown
        headers:
          Host: $V2_DOMAIN
        #max-early-data: 2048  # 用了就坏了
        #early-data-header-name: Sec-WebSocket-Protocol
      skip-cert-verify: true     #默认false
    EOF

    Screenshots

    notion image
     

    © Ying Bun 2021 - 2024