浏览器上的Nginx Ingress 404



为托管在nginx docker容器中的react应用程序创建了一个Ingress。

入口配置

apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: my-ingress
labels:
helm.sh/chart: home-service
app.kubernetes.io/name: home-service
app.kubernetes.io/instance: xrayed-vulture
app.kubernetes.io/version: "1.0.0"
app.kubernetes.io/managed-by: Tiller
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: "home-service.net"
http:
paths:
- path: "/pmr"
backend:
serviceName: my-service
servicePort: 8089

服务

apiVersion: v1
kind: Service
metadata:
name: my-service
labels:
helm.sh/chart: home-service
app.kubernetes.io/name: home-service
app.kubernetes.io/instance: xrayed-vulture
app.kubernetes.io/version: "1.0.0"
app.kubernetes.io/managed-by: Tiller
spec:
type: ClusterIP
ports:
- port: 8089
targetPort: 8089
protocol: TCP
name: http
- port: 443
targetPort: https
protocol: TCP
name: https
selector:
app.kubernetes.io/name: pmr-ui-app

我的react应用程序中的Nginx/etc/nginx/conf.d/default.conf配置,它托管在Nginx:稳定的高山容器中。

server {
listen 8089;
listen 443 default ssl;
server_name localhost;
root   /usr/share/nginx/html;
ssl_certificate /etc/nginx/certs/nginx.crt;
ssl_certificate_key /etc/nginx/certs/nginx.key;
ssl_protocols        SSLv3 TLSv1;
ssl_ciphers          HIGH:!aNULL:!MD5;
location / {
root   /usr/share/nginx/html;
index  index.html index.htm;
try_files $uri /index.html;
}
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page   500 502 503 504  /50x.html;
location = /50x.html {
root   /usr/share/nginx/html;
}
access_log /var/log/nginx/access.log main;
error_log   /var/log/nginx/error.log  warn;
}

对blow地址进行卷曲调用,入口工作正常并返回右侧页面

curl -v http://home-service.net/pmr

message from my nginx controller container
10.251.128.1 - - [02/Sep/2020:16:33:30 +0000] "GET /pmr HTTP/1.1" 200 3009 "-" "curl/7.64.0" 103 0.002 [nc-my-service-8089] [] 10.x.x.26:8089 3009 0.000 200 e2407a01ffcf7607b958522574979b29
message from the react app container itself
10.x.x.27 - - [02/Sep/2020:16:33:30 +0000] "GET /pmr HTTP/1.1" 200 3009 "-" "curl/7.64.0" "10.251.128.1"

但是访问浏览器时,我看到404加载了一些.js和css文件

http://home-service.net/pmr的Chrome

Nginx controller logs
10.x.x.198 - - [02/Sep/2020:14:45:36 +0000] "GET /pmr HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" 611 0.001 [nc-my-service-8089] [] 10.x.x.26:8089 0 0.000 304 f994cdb21f962002e73ce6d967f82550
10.x.x.200 - - [02/Sep/2020:14:51:11 +0000] "GET /wf-bridge/wf-bridge/wf-bridge.esm.js HTTP/1.1" 404 21 "http://home-service.net/pmr" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" 495 0.001 [upstream-default-backend] [] 10.x.x.18:8080 21 0.000 404 0ba3519a8f55673cdcbb391d6102609a
10.x.x.1 - - [02/Sep/2020:14:51:11 +0000] "GET /static/js/2.ae30464f.chunk.js HTTP/1.1" 404 21 "http://home-service.net/pmr" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" 435 0.001 [upstream-default-backend] [] 10.x.x.18:8080 21 0.000 404 b01b7b33a961df5be413f10ec14909c1
10.x.x.198 - - [02/Sep/2020:14:51:11 +0000] "GET /static/js/main.d76be073.chunk.js HTTP/1.1" 404 21 "http://home-service.net/pmr" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" 438 0.000 [upstream-default-backend] [] 10.x.x.18:8080 21 0.000 404 c333c6dca261a75133944c6e308874af
10.210.x.200 - - [02/Sep/2020:14:51:11 +0000] "GET /static/css/main.9d650a52.chunk.css HTTP/1.1" 404 21 "http://home-service.net/pmr" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" 455 0.000 [upstream-default-backend] [] 10.x.x.18:8080 21 0.000 404 0d8a5a6aa7d549294fcb1c147dd01294
10.x.x.198 - - [02/Sep/2020:14:51:11 +0000] "GET /static/js/2.ae30464f.chunk.js HTTP/1.1" 404 21 "http://kda9dc8056pmr01.aks.azure.ubsdev.net/pmr" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" 435 0.000 [upstream-default-backend] [] 10.x.x.18:8080 21 0.000 404 1d8ee795cfa4e52225cf51e9fc1989d6
10.x.x.198 - - [02/Sep/2020:14:51:11 +0000] "GET /static/js/main.d76be073.chunk.js HTTP/1.1" 404 21 "http://home-service.net/pmr" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" 438 0.001 [upstream-default-backend] [] 10.x.x.18:8080 21 0.004 404 a0952e173bfb58f418f5d600e377f18c
React Nginx container will recieve the request with 200 like this
10.x.x.25 - - [02/Sep/2020:14:25:27 +0000] "GET / HTTP/1.1" 200 3009 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36" "10.210.62.200"

为什么请求不是全部由my-service单独处理,而是由upstream-default-backend处理css和.js文件,从而导致404?

Nginx入口控制器版本:nginx-ingress-controller:0.26.1

您的资源使用根路径/static呈现。这是一个单独的HTTP请求,将获得默认的后端,因为它不满足/pmr路径规则。您应该在web应用程序中使用相对路径,以便反向代理正常工作。例如,去掉/根,只使用static/css/main.css。或者使用主机名规则而不是路径规则。

相关内容

  • 没有找到相关文章

最新更新