如何解决无法让资产为 ingress-nginx 后面的遗留 PHP 应用程序提供服务
所以这就是我想要做的,因为我的 /admin/v2
路由继续正常工作......但是,在 {{ 1}} 路线:
/admin
话虽如此,我可以使用以下内容正确加载资产,但随后 apiVersion: networking.k8s.io/v1
kind: Ingress
Metadata:
annotations:
kubernetes.io/ingress.class: "Nginx"
cert-manager.io/cluster-issuer: "letsencrypt-dev"
Nginx.ingress.kubernetes.io/ssl-redirect: "true"
name: ingress-dev
namespace: dev
spec:
tls:
- hosts:
- localhost
secretName: tls-localhost-dev
rules:
- host: localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: client-cluster-ip-service-dev
port:
number: 3000
- path: /admin
pathType: Prefix
backend:
service:
name: admin-cluster-ip-service-dev
port:
number: 4000
- path: /admin/v2
pathType: Prefix
backend:
service:
name: admin-v2-cluster-ip-service-dev
port:
number: 4001
- path: /api
pathType: Prefix
backend:
service:
name: api-cluster-ip-service-dev
port:
number: 5000
路线(或 /admin/v2
)不再有效,而是转到 /admin-v2
路线:
/admin
所以我想保留第一个配置,但还要为 apiVersion: networking.k8s.io/v1
kind: Ingress
Metadata:
annotations:
kubernetes.io/ingress.class: "Nginx"
cert-manager.io/cluster-issuer: "letsencrypt-dev"
Nginx.ingress.kubernetes.io/ssl-redirect: "true"
Nginx.ingress.kubernetes.io/add-base-url: "true"
Nginx.ingress.kubernetes.io/rewrite-target: /$1
Nginx.ingress.kubernetes.io/proxy-body-size: "0"
Nginx.org/client-max-body-size: "500m"
Nginx.ingress.kubernetes.io/use-regex: "true"
Nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite ^(/admin)$ $1/ permanent;
name: ingress-dev
namespace: dev
spec:
tls:
- hosts:
- localhost
secretName: tls-localhost-dev
rules:
- host: localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: client-cluster-ip-service-dev
port:
number: 3000
- path: /admin/?(.*)
pathType: Prefix
backend:
service:
name: admin-cluster-ip-service-dev
port:
number: 4000
- path: /admin/v2
pathType: Prefix
backend:
service:
name: admin-v2-cluster-ip-service-dev
port:
number: 4001
- path: /api
pathType: Prefix
backend:
service:
name: api-cluster-ip-service-dev
port:
number: 5000
正确加载静态资产,但我不知道该怎么做。
/admin
到 ingress-Nginx
的流量应该会流向在 Pod 中运行的 /admin
。我认为解决方案可能必须从那里来。这是它的配置:
Nginx
此外,这是在 server {
listen 4000;
# rewrite ^([^.]*[^/])$ $1/ permanent;
root /usr/share/Nginx/html/src;
include /etc/Nginx/default.d/*.conf;
index app.PHP index.PHP index.html index.htm;
client_max_body_size 500m;
location / {
try_files $uri $uri/ /index.PHP$is_args$args;
}
location ~ [^/]\.PHP(/|$) {
fastcgi_split_path_info ^(.+?\.PHP)(/.*)$;
# Mitigate https://httpoxy.org/ vulnerabilities
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
include fastcgi.conf;
}
}
HTML 模板文件中引用资产的方式,我曾尝试将 index.tbs
附加到该文件,但这只会使 URL admin/
当您在 Elements 选项卡中检查它时:
localhost/admin/admin/css/default.css
有关如何解决此问题的建议?
澄清一下,当我查看它试图提供的 <link rel="STYLESHEET" type="text/css" href="css/portal.css" />
<link rel="STYLESHEET" type="text/css" href="css/default.css" />
时,它只是为网站编译的 HTML。
编辑:
Nginx.conf
现在,当我到达 location / {
try_files $uri $uri/ /index.PHP$is_args$args;
rewrite ^/admin/(.*) /$1 break;
}
路线时,它可以正确地提供 CSS 资产,但随后我登录,这会将我定向到 localhost/admin
并显示“找不到文件”。所以我需要以某种方式将 localhost/admin/index.PHP
排除在外。
解决方法
好的,搞定了。也许不是最佳实践...
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: "letsencrypt-dev"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
# this is apparently needed otherwise it doesn't serve the assets
# trying to do this in nginx.conf,just automatically re-routes to
# localhost:4000/admin for some reason
nginx.ingress.kubernetes.io/configuration-snippet: |
rewrite ^(/admin)$ $1/ permanent;
name: ingress-dev
namespace: dev
spec:
tls:
- hosts:
- localhost
secretName: tls-localhost-dev
rules:
- host: localhost
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: client-cluster-ip-service-dev
port:
number: 3000
- path: /admin
pathType: Prefix
backend:
service:
name: admin-cluster-ip-service-dev
port:
number: 4000
- path: /admin/v2
pathType: Prefix
backend:
service:
name: admin-v2-cluster-ip-service-dev
port:
number: 4001
- path: /api
pathType: Prefix
backend:
service:
name: api-cluster-ip-service-dev
port:
number: 5000
server {
listen 4000;
root /usr/share/nginx/html/src;
include /etc/nginx/default.d/*.conf;
index app.php index.php index.html index.htm;
client_max_body_size 500m;
location / {
try_files $uri $uri/ /index.php$is_args$args;
rewrite ^/admin/?(.*) /$1 break;
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
rewrite ^/admin/?(.*) /$1 break;
fastcgi_param HTTP_PROXY "";
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。