Setup Proxy Server

Table of Contents

WebSocket+TLS+Web

v2ray server client setup

{
  "log": {
    "access": "/var/log/v2ray/access.log",
    "error": "/var/log/v2ray/error.log",
    "loglevel": "warning"
  },
  "routing": {
    "domainStrategy": "AsIs",
    "rules": [
      {
        "type": "field",
        "ip": [
          "geoip:private"
        ],
        "outboundTag": "block"
      }
    ]
  },
  "inbounds": [
    {
      "port": 789,
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "4e1c5285-2e60-4302-9f30-5d1aedf6d9eb",
            "level": 1,
            "alterId": 0
          }
        ]
      },
      "streamSettings": {
        "network": "tcp"
      },
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      }
    },
    {
      "listen": "127.0.0.1",
      "port": 10000,
      "protocol": "vmess",
      "settings": {
        "clients": [
          {
            "id": "bf1d82a2-640a-484e-83ea-3b30bc7a46da",
            "alterId": 0
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "wsSettings": {
          "path": "/ray"
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "tag": "block"
    }
  ]
}

v2ray client config

{
  "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": "proxy.example.com",
            "port": 443,
            "users": [
              {
                "id": "bf1d82a2-640a-484e-83ea-3b30bc7a46da",
                "alterId": 0
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "wsSettings": {
          "path": "/ray"
        }
      }
    }
  ]
}

Clash config

proxies:
  - name: "vmess"
    type: vmess
    server: proxy.example.com
    port: 443
    uuid: bf1d82a2-640a-484e-83ea-3b30bc7a46da
    alterId: 0
    cipher: auto
    tls: true
    skip-cert-verify: true
    network: ws
    ws-opts:
      path: /ray
      Host: example.com
      mux: false

Nginx

server {
    server_name proxy.example.com;

    listen 443 ssl;
    ssl on;
    ssl_certificate your_fullchains_cert.crt;
    ssl_certificate_key your_fullchains_cert.key;
    ssl_protocols         TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers           HIGH:!aNULL:!MD5;

    location /ray {
      if ($http_upgrade != "websocket") {
          return 404;
      }
      proxy_redirect off;
      proxy_pass http://127.0.0.1:10000/ray;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
      # Show real IP in v2ray access.log
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

server {
    listen 80;
    server_name proxy.example.com;
    rewrite ^(.*)$ https://example.com:443/$1 permanent;
}

测试

访问网站根目录

curl -s https://proxy.example.com

先通过普通的curl命令来连接

curl -s https://proxy.example.com/ray

带参数访问

curl -s --include --header "Upgrade: websocket" https://proxy.example.com/ray

Trouble Shoot

AH01144: No protocol handler was valid for the URL /ray (scheme 'ws').

尝试使用apache2来配置时,出现下面的问题,对apache2的配置不熟悉,暂未解决, 改用了nginx。

[Mon Mar 20 18:52:16.056911 2023] [proxy:warn] [pid 38602:tid 139868881540864] [client 18.117.95.84:34288] AH01144: No protocol handler was valid for the URL /ray (scheme 'ws'). If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

参考资料

Contact me via :)
虚怀乃若谷,水深则流缓。