Skip to content

LZC路由中转发到AI服务

一个简单的AI应用,只有一个算力舱中部署的服务,一些服务把界面这些也包括进去了。

服务在算力舱中部署后,可以通过 https://${服务名称}-ai.${微服名称}.heiyu.space 访问。

而在 LPK 应用的路由中,您可能会像下面这样子写

yml
routers:
  - /=https://${服务名称}-ai.${微服名称}.heiyu.space

微服 1.3.8+ 系统

使用 微服系统的 1.3.8 upstreams 特性实现

yml
application:
  upstreams:
    - location: /
      backend: https://comfyui-ai.{{ .S.BoxDomain }}
      use_backend_host: true
      dump_http_headers_when_5xx: true

使用模板manifest.yml

微服 1.3.8 之前的系统

这种情况下,您在路由中不能知道当前访问的 ${微服名称},所以需要一个转发工具来处理,比如 nginx 或者 caddy

yml
application:
  routes:
    - /=http://caddy:80

services:
  caddy:
    image: registry.lazycat.cloud/caddy:2.9.1-alpine
    setup_script: |
      cat <<'EOF' > /etc/caddy/Caddyfile
      {
          auto_https off
          http_port 80
          https_port 0
      }

      :80 {
          redir https://${服务名称}-ai.{$LAZYCAT_BOX_DOMAIN} permanent
      }
      EOF
      cat /etc/caddy/Caddyfile