v2fly/v2ray-examples

repository·master·Indexed 25 days ago

https://github.com/v2fly/v2ray-examples

A repository of V2Ray configuration examples for clients and servers. It provides JSON templates for VMess, VLESS, and Shadowsocks, along with specific setup guides for gRPC, WebSocket, and H2C. Includes version requirements for NGINX (1.13.10+), V2Ray-Core (v4.36.0+), and Caddy2 (v2.2.0-rc.1+), as well as guidelines for creating configuration templates and advice on choosing protocols based on network environments.

Tokens
7K
Snippets
19
Records
30
Agent score
81%

What's inside v2ray-examples

  1. Architecture of VLESS over H2C with Caddy2

    master

    This configuration implements a proxy chain using VLESS, HTTP/2 (H2), and HTTP/2 Cleartext (H2C) to route traffic from a client to a server through a Caddy2 instance.

    Traffic Flow: v2ray client <--- H2 (HTTP/2) ---> caddy2 <--- H2C (HTTP/2 Cleartext) ---> v2ray server

    This setup allows the client to communicate with Caddy2 using standard encrypted HTTP/2, while Caddy2 communicates with the backend V2Ray server using H2C.

    v2ray client <--- H2 ---> caddy2 <--- H2C ---> v2ray server
  2. How SOCKS5 over TLS is detected via active probing

    master

    Detectors can identify SOCKS5/TLS services by observing specific byte sequences during the SOCKS5 handshake over a TLS connection.

    Typical response patterns include:

    • If a client sends 05 01 01, a server responding with 05 ff indicates the service is SOCKS5/TLS.
    • If a client sends 05 02 00 02 (attempting username/password authentication), a server responding with 05 00 or 05 02 confirms the service identity.
    -> 05 01 01
    <- 05 ff
    
    -> 05 02 00 02
    <- 05 00 / 05 02
  3. V2Ray Configuration Template Standards

    master

    When creating or modifying V2Ray configuration templates, adhere to these standards to ensure compatibility and cleanliness:

    • Indentation: Use 4 spaces.
    • Brackets: Do not wrap square (curly) brackets.
    • Cleanup: Remove unneeded fields. In the log section, only include loglevel.
    • Outbounds:
      • Client-side configurations should include proxy and direct tags.
      • Server-side configurations should include direct and block tags.
    • Routing: Unless specific to a scenario, geoip:private should be routed to the direct outbound on the client side, and to the block outbound on the server side.
    • DNS: Do not include DNS in config files unless it is a specific scenario template.
    • Security: Leave the uuid field blank so users can fill it in themselves.
    • Domain Strategy: Keep domainStrategy in routing at its default value: AsIs.
  4. How to choose a V2Ray configuration

    master

    Choosing the right configuration depends on your specific network environment and QoS (Quality of Service) levels in your region.

    Key Advice:

    • While Websocket + TLS + Web is considered a highly robust solution, it is not recommended for beginners to start with.
    • Network conditions vary by region. The best approach is to test different protocols to find what works best for your specific connection. Avoid assuming why a connection is slow without testing alternatives.
  5. Generate the V2Ray plan flowchart PNG

    master

    After modifying the how-to-choose-a-v2ray-plan.mmd file, use the mmdc command from mermaid.cli to generate the updated how-to-choose-a-v2ray-plan.png file. The command requires specifying the input file, output file, theme, style, dimensions, and Puppeteer configuration.

    ./node_modules/.bin/mmdc -i how-to-choose-a-v2ray-plan.mmd -o how-to-choose-a-v2ray-plan.png -t forest -C style.css -w 1920 -H 1080 -p puppeteer-config.json
  6. Prerequisites for VLESS over TCP with TLS + Fallback

    master

    To implement the minimal VLESS over TCP with TLS and fallback configuration, you must satisfy the following requirements:

    1. Domain Name: A domain name pointing to your server's IP address.
    2. SSL Certificate: A valid certificate for your domain (e.g., obtained via Let's Encrypt).
    3. Web Server: A web server such as Nginx or Caddy to handle the fallback traffic.
    4. Network Access: Ensure that ports 80 (HTTP) and 443 (HTTPS) are open in your server's firewall or VPS security groups.
  7. Use VLESS over TCP with TLS and WebSocket fallback/splitting

    master

    This advanced configuration is a superset of the minimal VLESS over TCP with TLS setup. It leverages VLESS's fallback and splitting capabilities to allow VLESS over TCP with TLS and any WebSocket Secure (WSS) connection to coexist on port 443.

    Key benefits:

    • Coexistence: You can connect via VLESS over TCP with TLS and any WebSocket with TLS simultaneously on the same port.
    • CDN Compatibility: The WebSocket (WSS) connection path can be routed through a CDN.
    • Performance: Using VLESS fallback/splitting for WebSocket is more performant than using Nginx as a reverse proxy for WebSocket.
    • Flexibility: You can replace VLESS on the WebSocket side with other protocols like VMess, or configure multiple PATHs and protocols.
  8. Install mermaid.cli to update the decision flowchart

    master

    To modify the how-to-choose-a-v2ray-plan.mmd flowchart and regenerate the PNG image, you must install mermaid.cli. If you are in a region requiring a mirror for Puppeteer downloads, configure the puppeteer_download_host before installing.

    # If using yarn and needing a mirror:
    yarn config set puppeteer_download_host https://npm.taobao.org/mirrors
    yarn add mermaid.cli
    
    # If using npm and needing a mirror:
    npm config set puppeteer_download_host=https://npm.taobao.org/mirrors
    npm install mermaid.cli
  9. Configure VLESS over TCP with TLS and Fallback (Website Hosting)

    master

    This configuration is designed for users who need to host a website alongside their V2Ray service using VLESS over TCP with TLS and Fallback. It utilizes advanced VLESS fallback features to route traffic to a local web server (like Nginx) while maintaining proxy functionality.

    Key Features

    • PROXY protocol: Used to pass the real source IP and port of the request to the backend.
    • h2 support: If the ALPN negotiation results in h2, the traffic is forwarded separately.
    • Unix domain socket: Uses a Unix domain socket for communication between V2Ray and the web server, which is more efficient than using a loopback address.

    Nginx Implementation Details

    • The provided nginx.conf is based on the Nginx configuration used by CentOS 8 dnf.
    • HTTP to HTTPS Redirection: All HTTP requests on port 80 are automatically redirected (301) to HTTPS.
    • Socket Management: When restarting Nginx, you may need to manually delete the socket file that Nginx is bound to.

    Troubleshooting and Logging

    • V2Ray Logs: Check the V2Ray server's info level error logs to see detailed reasons for every fallback event.
    • Nginx Logs: The real source IP and port of the request are appended to the end of each line in the Nginx access log.
  10. Configure V2Ray with Domain Socket for Shadowsocks-Websocket-Web-TLS

    master

    When using the Domain Socket approach (via config_server_domainsocket.json), you must ensure the system service has permission to create the socket directory. By default, the v2ray service runs as the nobody user, which lacks permissions to create folders in /var/run.

    To fix this, you must modify the systemd service file to use RuntimeDirectory. This ensures that the directory specified in your config.json under dsSettings.path (e.g., /var/run/ss-loop) is correctly managed by systemd.

    Note: If you update V2Ray using the FHS script, your changes to the service file will be overwritten and you must repeat these steps.

    # Add this to the [Service] section of /etc/systemd/system/v2ray.service
    RuntimeDirectory=ss-loop

    Then execute these commands to apply changes:

    systemctl disable v2ray.service
    systemctl enable v2ray.service
    systemctl restart v2ray