gpt4 book ai didi

angular - 使用 Ingress Gateway 子文件夹 React 应用程序 + Angular 应用程序时出现问题

转载 作者:行者123 更新时间:2023-12-02 11:43:09 31 4
gpt4 key购买 nike

尝试通过 minikube 中的 Istio 网关访问 webapp 前端时遇到问题。我已经将入口网关配置为为 Angular 前端 (minikube_ip:31380/home) 和 React 前端 (minikube_ip:31380/app) 提供服务,但是当我尝试访问时,找不到 404 个文件(css、assets、main.js、 bundle.js 等)--> 404 Error Screenshot

我尝试在构建命令“主页”:“。”中编写 --base-href/app在 package.json 中,"homepage": "/app"在 package.json 中,没有任何改变。

唯一改变 http 响应的是 index.html (Angular) 中的以下标记:

  <base href="/home/">

index.html( react ):
  <base href="/app/">

结果是下一个:
Angular 应用程序 --> Angular project error
React 应用程序 --> React project error

nginx.conf:
server {

listen 80;

sendfile on;

default_type application/octet-stream;


gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 1100;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;


root /usr/share/nginx/html;


location / {
try_files $uri $uri/ /index.html =404;
}

}

我的 Istio 入口规则:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: ingress-gateway-configuration
spec:
selector:
istio: ingressgateway
servers:
- port:
number: 80
name: http
protocol: HTTP
hosts:
- "*"
---
kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
name: virtual-service
namespace: default
spec:
hosts:
- "*"
gateways:
- ingress-gateway-configuration

http:

- match:
- uri:
prefix: /app
route:
- destination:
host: webapp-service
subset: app

- match:
- uri:
prefix: /home
route:
- destination:
host: webapp-service
subset: home


---
kind: DestinationRule
apiVersion: networking.istio.io/v1alpha3
metadata:
name: destination-rule
namespace: default
spec:
host: webapp-service
subsets:
- labels:
version: home
name: home
- labels:
version: app
name: app

主要问题:
MAIN PROBLEM

最后,补充一点,我已经将显示两个前端的模式从 Ingress Gateway 更改为 NodePort,并通过 NodePort 访问它们显示良好(例如:minikube_ip:31040)。

提前致谢。

最佳答案

尝试修改您的入口对象重写目标和路径,如下所示:

   nginx.ingress.kubernetes.io/rewrite-target: /$1
path: /(.*)

并确保你检查了这个 documentation

一旦你尝试过,请告诉我。

关于angular - 使用 Ingress Gateway 子文件夹 React 应用程序 + Angular 应用程序时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58843190/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com