站点与 Xray 共用 443 反向代理

  网站域名访问与 Xray 的端口均使用 443,会导致网站域名不能访问或者 Xray 端口协议受阻,本教程是实现网站与 Xray 共用 443 端口,实现两者同时均可使用 443 端口,网站域名和 Xray 协议也可同时正常工作。

  教程依旧使用云服务器搭建,在同一台服务器上同时运行:

  VLESS TCP TLS Vision → 443
  VLESS Reality Vision → 443 或配置端口
  Xray 伪装站 → https://1101.10181128.xyz → root /usr/share/nginx/html/
  Komari 面板 → https://komari.10181128.xyz → 127.0.0.1:8083
  Openlist 网盘 → https://alist.10181128.xyz → 127.0.0.1:5244

  可以实现:浏览器 / 代理客户端 → 443 → Xray → 【普通 HTTPS 请求 → fallback → 系统 Nginx → Komari:8083】/ 【VLESS / Reality 请求 → Xray 正常处理】

  简介:

  本教程使用 Docker 安装的 Komari 面板和 Openlist 网盘、一键脚本安装的 Xray TLS/TCP 协议,通过 fallback 到系统 Nginx 的回落实现 443 端口的共用和反向代理。

准备工作

  1. 一台服务器,并获取该服务器公网 IP 。
  2. 域名已解析。
  3. Xray TLS/TCP 协议已搭建。
  4. Komari 或者 Openlist 已搭建。

一、部署 Komari 探针面板和 Openlist 网盘

仅使用脚本安装 Docker 版本的 Komari 和 Openlist,域名反代在系统 Nginx 中设置。

二、部署 Xray TLS/TCP 协议

仅使用脚本安装 Xray TLS/TCP 服务。并确认已存在以下文件:

1
2
/etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json
/etc/nginx/conf.d/alone.conf

Komari 容器只监听自己的服务端口,例如:

1
0.0.0.0:8083->25774/tcp

不能让 Docker Nginx 占用 80/443。

三、确认端口状态

  1. 执行:

    1
    2
    docker ps -a
    ss -lntup | grep -E ':80|:443|:8083|:5244'

    理想状态:

    1
    2
    3
    443 -> xray
    8083 -> komari
    5244 -> openlist
  2. 如果看到 Docker Nginx 占用 80/443 端口,则需要停止 Docker Nginx:

    1
    2
    docker stop nginx
    docker update --restart=no nginx
  3. 确认不再需要后删除 Docker Nginx:

    1
    docker rm nginx

四、确认 Xray fallback 已存在

查看配置文件:

1
cat /etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json

应该看到以下内容:

1
2
3
4
5
6
7
8
9
10
11
"fallbacks": [ 
{
"dest": 31300,
"xver": 1
},
{
"alpn": "h2",
"dest": 31302,
"xver": 1
}
]

这说明 Xray 443 → fallback 到 Nginx 31300 / 31302。 Xray 已经配置了 fallback,31300 是普通 HTTPS 请求的回落端口,31302 是 HTTP/2 回落端口。

五、申请 Komari / Openlist 子域名证书

假设 Komari 域名是 komari.10181128.xyz,Openlist 域名是 alist.10181128.xyz

  1. 需要先确认 DNS 已解析到当前服务器 IP。

    1
    2
    3
    dig +short komari.10181128.xyz
    dig +short alist.10181128.xyz
    curl -4 ip.sb
  2. 然后申请证书:

    1
    2
    3
    4
    5
    6
    7
    8
    # 申请 Komari 域名证书
    systemctl stop nginx
    systemctl stop xray
    ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
    ~/.acme.sh/acme.sh --issue -d komari.10181128.xyz --standalone --keylength ec-256 --server letsencrypt
    ~/.acme.sh/acme.sh --install-cert -d komari.10181128.xyz --ecc \
    --key-file /etc/v2ray-agent/tls/komari.10181128.xyz.key \
    --fullchain-file /etc/v2ray-agent/tls/komari.10181128.xyz.crt
    1
    2
    3
    4
    5
    6
    7
    8
    # 申请 Openlist 域名证书
    systemctl stop nginx
    systemctl stop xray
    ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
    ~/.acme.sh/acme.sh --issue -d alist.10181128.xyz --standalone --keylength ec-256 --server letsencrypt
    ~/.acme.sh/acme.sh --install-cert -d alist.10181128.xyz --ecc \
    --key-file /etc/v2ray-agent/tls/alist.10181128.xyz.key \
    --fullchain-file /etc/v2ray-agent/tls/alist.10181128.xyz.crt

    申请成功后,显示如下:

    1
    2
    Cert success.
    Installing full chain to: /etc/v2ray-agent/tls/komari.10181128.xyz.crt

六、把域名证书加入 Xray

  1. 备份配置文件 02_VLESS_TCP_inbounds.json:

    1
    cp /etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json /root/02_VLESS_TCP_inbounds.json.bak
  2. 编辑配置文件 02_VLESS_TCP_inbounds.json:

    1
    nano /etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json

    找到:

    1
    2
    3
    4
    5
    6
    7
    "certificates": [ 
    {
    "certificateFile": "/etc/v2ray-agent/tls/1101.10181128.xyz.crt",
    "keyFile": "/etc/v2ray-agent/tls/1101.10181128.xyz.key",
    "ocspStapling": 3600
    }
    ]

    改成:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    "certificates": [ 
    {
    "certificateFile": "/etc/v2ray-agent/tls/1101.10181128.xyz.crt",
    "keyFile": "/etc/v2ray-agent/tls/1101.10181128.xyz.key",
    "ocspStapling": 3600
    },
    {
    "certificateFile": "/etc/v2ray-agent/tls/komari.10181128.xyz.crt",
    "keyFile": "/etc/v2ray-agent/tls/komari.10181128.xyz.key",
    "ocspStapling": 3600
    },
    {
    "certificateFile": "/etc/v2ray-agent/tls/alist.10181128.xyz.crt",
    "keyFile": "/etc/v2ray-agent/tls/alist.10181128.xyz.key",
    "ocspStapling": 3600
    }
    ]

    注意 JSON 逗号必须正确。

七、修改系统 Nginx fallback 配置

  1. 备份配置文件 alone.conf:

    1
    cp /etc/nginx/conf.d/alone.conf /root/alone.conf.bak
  2. 编辑配置文件 alone.conf:

    • 若每个域名都对应不同的站点,则:

      1
      nano /etc/nginx/conf.d/alone.conf

      修改 server_name 为 Komari 和 Openlist 域名,并且增加 location{} 内容:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      100
      101
      102
      103
      104
      105
      106
      107
      108
      109
      110
      111
      112
      113
      114
      115
      116
      117
      118
      119
      120
      121
      122
      123
      124
      125
      126
      127
      128
      129
      130
      131
      132
      133
      134
      135
      136
      137
      138
      139
      140
      141
      142
      143
      144
      server {
      listen 127.0.0.1:31300;
      server_name _;
      return 403;
      }

      # 代理伪装站主域名 - HTTP/2 fallback
      server {
      listen 127.0.0.1:31302 so_keepalive=on proxy_protocol;
      http2 on;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name 1101.10181128.xyz;
      root /usr/share/nginx/html/;

      location / {
      }
      }

      # 代理伪装站主域名 - HTTP/1.1 fallback
      server {
      listen 127.0.0.1:31300 proxy_protocol;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name 1101.10181128.xyz;
      root /usr/share/nginx/html/;

      location / {
      }
      }

      # Komari - HTTP/2 fallback
      server {
      listen 127.0.0.1:31302;
      http2 on;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name komari.10181128.xyz;

      location / {
      proxy_pass http://127.0.0.1:8083;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      client_max_body_size 1000m;
      }
      }

      # Komari - HTTP/1.1 fallback
      server {
      listen 127.0.0.1:31300;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name komari.10181128.xyz;

      location / {
      proxy_pass http://127.0.0.1:8083;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      client_max_body_size 1000m;
      }
      }

      # OpenList - HTTP/2 fallback
      server {
      listen 127.0.0.1:31302;
      http2 on;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name alist.10181128.xyz;

      location / {
      proxy_pass http://127.0.0.1:5244;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      proxy_read_timeout 300s;
      proxy_send_timeout 300s;
      proxy_request_buffering off;

      client_max_body_size 4000m;
      }
      }

      # OpenList - HTTP/1.1 fallback
      server {
      listen 127.0.0.1:31300;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name alist.10181128.xyz;

      location / {
      proxy_pass http://127.0.0.1:5244;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      proxy_read_timeout 300s;
      proxy_send_timeout 300s;
      proxy_request_buffering off;

      client_max_body_size 4000m;
      }
      }
    • 若伪装站点设置为某一网站相同的内容,则:

      1
      nano /etc/nginx/conf.d/alone.conf

      修改 server_name 为 伪装站点、Komari 和 Openlist 域名,并且增加 location{} 内容:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
      100
      101
      102
      103
      104
      105
      106
      107
      108
      109
      110
      111
      112
      113
      114
      115
      116
      117
      server {
      listen 127.0.0.1:31300;
      server_name _;
      return 403;
      }

      # 代理伪装站和 Komari 主域名 - HTTP/2 fallback
      server {
      listen 127.0.0.1:31302 so_keepalive=on proxy_protocol;
      http2 on;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name 1101.10181128.xyz komari.10181128.xyz;
      root /usr/share/nginx/html/;

      location / {
      proxy_pass http://127.0.0.1:8083;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      client_max_body_size 1000m;
      }
      }

      # 代理伪装站和 Komari 主域名 - HTTP/1.1 fallback
      server {
      listen 127.0.0.1:31300 proxy_protocol;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name 1101.10181128.xyz komari.10181128.xyz;
      root /usr/share/nginx/html/;

      location / {
      proxy_pass http://127.0.0.1:8083;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      client_max_body_size 1000m;
      }
      }

      # OpenList - HTTP/2 fallback
      server {
      listen 127.0.0.1:31302;
      http2 on;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name alist.10181128.xyz;

      location / {
      proxy_pass http://127.0.0.1:5244;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      proxy_read_timeout 300s;
      proxy_send_timeout 300s;
      proxy_request_buffering off;

      client_max_body_size 4000m;
      }
      }

      # OpenList - HTTP/1.1 fallback
      server {
      listen 127.0.0.1:31300;

      set_real_ip_from 127.0.0.1;
      real_ip_header proxy_protocol;

      server_name alist.10181128.xyz;

      location / {
      proxy_pass http://127.0.0.1:5244;
      proxy_http_version 1.1;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $proxy_protocol_addr;
      proxy_set_header X-Forwarded-For $proxy_protocol_addr;
      proxy_set_header X-Forwarded-Proto https;

      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";

      proxy_read_timeout 300s;
      proxy_send_timeout 300s;
      proxy_request_buffering off;

      client_max_body_size 4000m;
      }
      }
      • 31300 是 HTTP/1.1 fallback 入口,proxy_protocol 用于接收 Xray fallback 传来的真实客户端 IP 信息。由于 Xray fallback 配置中使用了 xver: 1,因此 Nginx 监听 31300 时也必须启用 proxy_protocol,并通过 real_ip_header proxy_protocol 解析真实 IP。
      • 31302 是 HTTP/2 fallback 入口,作用与 31300 类似,但用于处理 ALPN 为 h2 的 HTTP/2 请求。因此该端口除了 proxy_protocol 外,还需要开启 http2 on。so_keepalive=on 用于启用 TCP keepalive,提高长连接稳定性。

      其中,

      1
      2
      3
      127.0.0.1:443  -> Xray
      127.0.0.1:8083 -> Komari 面板
      127.0.0.1:5244 -> Openlist 网盘

      要替换成自己的 Komari 和 Openlist 容器端口。

      • 不同业务域名必须拆分不同 server 块,不能全部写在同一个 server_name 后面。
      • 注意:如果多个 server 块监听相同的 IP 和端口,只有第一个 server 块需要写完整的 listen 参数,例如 so_keepalive=on、proxy_protocol;后续相同端口的 server 块只保留 listen 127.0.0.1:31302; 或 listen 127.0.0.1:31300;,否则 nginx -t 会报 duplicate listen options。

八、测试配置并重启

  1. 测试 Nginx 配置:

    1
    2
    nginx -t
    /etc/v2ray-agent/xray/xray run -test -confdir /etc/v2ray-agent/xray/conf

    如果看到:

    1
    2
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    Configuration OK.

    说明配置正确。

  2. 最后必须重启 Xray 和 Nginx:

    1
    2
    systemctl restart xray
    systemctl restart nginx
    • systemctl reload nginx 会重新加载 Nginx 配置,而 systemctl restart nginx 会重启系统 Nginx 服务。这里建议使用 restart,确保 Nginx 监听的 31300 / 31302 端口生效。
    • 修改 /etc/nginx/conf.d/alone.conf 后,必须执行 nginx -t 检查语法,并 reload 或 restart Nginx,否则浏览器访问的仍然是旧配置。

    然后确认 Nginx 真的加载或者重启成功:

    1
    systemctl status nginx --no-pager

九、测试访问

  1. 测试网站,打开以下网页:

    1
    2
    3
    https://1101.10181128.xyz
    https://komari.10181128.xyz
    https://alist.10181128.xyz
  2. 测试 Xray 协议是否正常工作:

    1
    2
    3
    4
    VLESS TCP/TLS Vision
    VLESS Reality Vision
    Hysteria2
    TUIC

若以上测试均正常,则说明网站与 Xray 共用 443 端口反向代理成功。

十、共用 443 成功后的端口状态

执行:

1
2
docker ps -a
ss -lntup | grep -E ':80|:443|:8083|:5244'

理想状态:

1
2
3
443 -> xray
8083 -> docker-proxy-komari
5244 -> docker-proxy-alist

如果 Docker Nginx 再次出现并占用 80/443 端口,则需要停止 Docker Nginx:

1
2
docker stop nginx
docker update --restart=no nginx

十一、备份当前可用配置

成功后务必备份当前可用配置,避免误操作导致 Xray 或 Nginx 配置丢失。

1
2
3
4
5
mkdir -p /root/v2ray-backup
cp /etc/nginx/conf.d/alone.conf /root/v2ray-backup/
cp /etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json /root/v2ray-backup/
cp /etc/v2ray-agent/tls/*.crt /root/v2ray-backup/
cp /etc/v2ray-agent/tls/*.key /root/v2ray-backup/

十二、常见问题

  1. VLESS TLS / Reality 突然不通,检查检查 443 是否被 nginx 或 Docker 抢占:

    1
    2
    ss -lntup | grep -E ':80|:443'
    lsof -iTCP:443 -sTCP:LISTEN -P -n

    正常应为:

    1
    xray *:443

    如果看到 Docker Nginx 占用 443,则停止 Docker Nginx:

    1
    2
    docker stop nginx
    docker update --restart=no nginx
  2. 证书过期导致 TLS 节点不通

    • 检查证书是否过期:

      1
      2
      3
      openssl s_client -connect 1101.10181128.xyz:443 -servername 1101.10181128.xyz -brief
      openssl s_client -connect komari.10181128.xyz:443 -servername komari.10181128.xyz -brief
      openssl s_client -connect alist.10181128.xyz:443 -servername alist.10181128.xyz -brief
    • 如果出现证书过期或者以下错误:

      1
      self-signed certificate
    • 则需要根据不同的域名重新续签证书:

      1
      2
      3
      4
      5
      6
      7
      8
      # 申请 Komari 域名证书
      systemctl stop nginx
      systemctl stop xray
      ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
      ~/.acme.sh/acme.sh --issue -d komari.10181128.xyz --standalone --keylength ec-256 --server letsencrypt
      ~/.acme.sh/acme.sh --install-cert -d komari.10181128.xyz --ecc \
      --key-file /etc/v2ray-agent/tls/komari.10181128.xyz.key \
      --fullchain-file /etc/v2ray-agent/tls/komari.10181128.xyz.crt
      1
      2
      3
      4
      5
      6
      7
      8
      # 申请 Openlist 域名证书
      systemctl stop nginx
      systemctl stop xray
      ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
      ~/.acme.sh/acme.sh --issue -d alist.10181128.xyz --standalone --keylength ec-256 --server letsencrypt
      ~/.acme.sh/acme.sh --install-cert -d alist.10181128.xyz --ecc \
      --key-file /etc/v2ray-agent/tls/alist.10181128.xyz.key \
      --fullchain-file /etc/v2ray-agent/tls/alist.10181128.xyz.crt

      申请成功后,显示如下:

      1
      2
      Cert success.
      Installing full chain to: /etc/v2ray-agent/tls/komari.10181128.xyz.crt
    • 续签成功后,要重启 Xray 和 Nginx:

      1
      2
      systemctl restart xray
      systemctl restart nginx
  3. acme.sh 使用 ZeroSSL 申请证书报错

    如果出现:

    1
    Please update your account with an email address first.

    切换到 Let’s Encrypt 重新申请证书:

    1
    ~/.acme.sh/acme.sh --set-default-ca --server letsencrypt
  4. Komari / Openlist 的 HTTP 网页能打开但无法登录

    说明需要 HTTPS 或者 WebSocket 头部支持,请确认 Nginx 配置文件中是否有以下内容:

    1
    2
    3
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header X-Forwarded-Proto https;
  5. 若将配置文件修改错了,可使用备份文件恢复:

    • 恢复 Xray :

      1
      2
      cp /root/02_VLESS_TCP_inbounds.json.bak /etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json
      systemctl restart xray
    • 恢复 Nginx :

      1
      2
      3
      cp /root/alone.conf.bak /etc/nginx/conf.d/alone.conf
      nginx -t
      systemctl restart nginx

十三、以后新增其他服务的标准流程

假设新增一个域名 new.10181128.xyz,服务端口为 8080,并且需要共用 443 端口。

流程如下

  1. DNS 解析 new.10181128.xyz 到 服务器公网 IP
  2. acme.sh 申请 new 证书
  3. 把证书加入 Xray certificates
  4. 新增 new.10181128.xyz 域名的 server 块,并将 proxy_pass 指向该服务器真实端口,例如 127.0.0.1:8080
  5. nginx -t
  6. xray run -test
  7. 重启 xray 和 nginx

核心原则

443 永远给 Xray
业务服务只监听本地端口
Nginx 只监听 127.0.0.1:31300 / 31302
Docker 不要再占用 80/443

发布于

2026-07-10

更新于

2026-07-10

许可协议

评论

:D 一言句子获取中...