You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法使用通配符DNS,基于nginx-controller部署多静态应用咨询

Single DNS Record + Path Prefixes: How to Make It Work

Yes, you can deploy all your apps under one DNS record using path prefixes with nginx-ingress. The problem you hit is that your frontend apps use absolute asset paths (like /css/...), which skip the prefix and cause unrecognized requests. Here's how to fix this with two practical approaches:

1. Configure Apps to Use the Path Prefix (Best Option)

Most modern frontend tools (including ArgoCD and Dependency-Track) let you set a base path natively. This is cleaner than rewriting responses later.

For ArgoCD:

Edit the ArgoCD ConfigMap to add the base href:

apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-cm
  namespace: argocd
data:
  server.basehref: "/argocd/"

Restart the ArgoCD server pod after making this change. All asset URLs in the UI will now automatically use /argocd/css/... instead of /css/....

For Dependency-Track:

Set the BASE_URL environment variable for the UI service:

BASE_URL=/dependency-track/

Restart the Dependency-Track UI, and it will generate asset paths with the prefix included.

Once the apps are configured, use this simplified Ingress rule:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: multi-app-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: route.com
    http:
      paths:
      - path: /argocd(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: argocd-server
            port: { number: 80 }
      - path: /dependency-track(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: dependency-track-ui
            port: { number: 8080 }

2. Rewrite Asset Paths with Nginx Subfilter (Workaround)

If you can't modify the app configs (unlikely but possible), use nginx's sub_filter to rewrite absolute paths in HTML responses before sending them to the browser.

Example Ingress for ArgoCD:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: argocd-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/configuration-snippet: |
      sub_filter '/css/' '/argocd/css/';
      sub_filter '/js/' '/argocd/js/';
      sub_filter '/assets/' '/argocd/assets/';
      sub_filter_once off;
spec:
  rules:
  - host: route.com
    http:
      paths:
      - path: /argocd(/|$)(.*)
        pathType: Prefix
        backend:
          service:
            name: argocd-server
            port: { number: 80 }

Copy this pattern for Dependency-Track, swapping /argocd/ with /dependency-track/ in the sub_filter lines. Add more lines for other asset types (like /img/ or /fonts/) if the app uses them.

Why Your Earlier Attempt Failed

Your rewrite rule only handled the initial /argocd/ request, but the frontend was still telling the browser to fetch /css/... directly. The browser doesn't know about the path prefix unless the app's HTML explicitly uses it—either by configuring the app to add the prefix, or by nginx rewriting the HTML to include it.

内容的提问来源于stack exchange,提问作者TedEllis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 08:00:25