在Nginx Ingress AKS上设置Angular应用程序



我在Azure Kubernetes中部署了一个Angular SPA应用程序。我试图通过Ingress Nginx控制器访问该应用程序。Ingress指向xxx.xxx.com,应用程序部署在路径"/"中。因此,当我访问应用程序时,应用程序加载良好。但是,当我试图通过直接在浏览器(例如:eee.com/homepage(中输入index.html之外的任何其他页面来导航时,我会得到404 Not Found。

以下是码头文件内容

# base image
FROM nginx:1.16.0-alpine
# copy artifact build from the 'build environment'
COPY ./app/ /usr/share/nginx/html/
RUN rm -f /etc/nginx/conf.d/nginx.config
COPY ./nginx.config /etc/nginx/conf.d/nginx.config
# expose port 80
EXPOSE 80
# run nginx
CMD ["nginx", "-g", "daemon off;"]

Ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: app-frontend-ingress
namespace: app
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/add-base-url: "true"
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
tls:
- hosts:
- xxx.com
secretName: tls-dev-app-ingress
rules:
- host: xxx.com
http:
paths:
- backend:
serviceName: poc-service
servicePort: 80
path: /

nginx.conf

server {
listen 80;
location / {
root   /usr/share/nginx/html;
index  index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}
}

您可以添加一个配置片段,负责重写/:的任何路径

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: app-frontend-ingress
namespace: app
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: "true"    
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite /([^.]+)$ / break;
[...]

例如,如果您转到host.com/xyz,它将被重定向到host.com

相关内容

  • 没有找到相关文章

最新更新