HTTP/2

The HTTP/2 is the next generation of HTTP/1.1 protocol (although most of the HTTP servers still run HTTP/1.1). You can see the demo, which let you directly see that improvement of HTTP/2 compared to HTTP/1.1 (it is not guaranteed that HTTP/2 of V2Ray have same performance). We call the HTTP/2 protocol as h2 for simplicity.

It is usually compared by the users between the protocol of HTTP/2 or WebSocket. In theory, when HTTP/2 is connected for the first time, unlike WebSocket, it needs to complete the upgrade request. The V2Ray client and the server generally communicate directly, and there are fewer middle-tier proxies. However, in the application scenario of the CDN, Nginx/Caddy/Apache and other service components as the pre-split proxy, HTTP/2 is not flexible as WebSocket. As for many proxies do not provide back-end support for the HTTP/2 or HTTP/2 over TCP protocol. For actual using, the difference between WebSocket and HTTP/2 may not be obvious. You can choose according to your needs.

Configuration Example

It is configured in streamSettings just like any other transport layer protocol, but note that using HTTP/2 is required to enable TLS.

Server-side Configuration

{
  "inbounds": [
    {
      "port": 443,
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "b831381d-6324-4d53-ad4f-8cda48b30811",
            "alterId": 64
          }
        ]
      },
      "streamSettings": {
        "network": "h2", // h2 can write as http, they are the same
        "httpSettings": { // This term is setting of HTTP/2
          "path": "/ray"
        },
        "security": "tls", // Enable tls
        "tlsSettings": {
          "certificates": [
            {
              "certificateFile": "/etc/v2ray/v2ray.crt", // Certificate file, see in tls section
              "keyFile": "/etc/v2ray/v2ray.key" // Key file
            }
          ]
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "settings": {}
    }
  ]
}

Client-side Configuration

{
  "inbounds": [
    {
      "port": 1080,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": ["http", "tls"]
      },
      "settings": {
        "auth": "noauth",
        "udp": false
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "vmess",
      "settings": {
        "vnext": [
          {
            "address": "mydomain.me",
            "port": 443,
            "users": [
              {
                "id": "b831381d-6324-4d53-ad4f-8cda48b30811",
                "alterId": 64
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "h2",
        "httpSettings": { // This term is setting of HTTP/2 
          "path": "/ray"
        },
        "security": "tls"
      }
    }
  ]
}

Updates

  • 2018-03-18 Initial Version
  • 2018-08-30 Update
  • 2018-11-17 Adapted for V4.0+
  • 2019-7-11 New H2 description
Last Updated: 5/27/2020, 2:38:01 AM