我在Kubernetes集群上创建了这个入口和服务
apiVersion: v1
metadata:
name: google-storage-buckets
spec:
type: ExternalName
externalName: storage.googleapis.com
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: proxy-assets-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /kinto-static-websites/gatsby/public/$1
nginx.ingress.kubernetes.io/upstream-vhost: "storage.googleapis.com"
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
spec:
rules:
- host: gatsby.vegeta.kintohub.net
http:
paths:
- path: /(.*)$
backend:
serviceName: google-storage-buckets
servicePort: 443但是,只有当我在gatsby.vegeta.kintohub.net之后添加index.html时,这才起作用。
如果我登录gatsby.lavea.kintohub.net/page-2,也是如此。
我怎么才能让它工作起来呢?
谢谢
发布于 2020-08-10 11:52:35
这里更多的是关于你的nginx.conf,以及它认为它是?的默认文件。
默认的入口配置没有像总是尝试index.html这样的东西,所以您需要向您的Ingress Kubernetes资源添加一些额外的配置。对于nginx入口控制器,您可以使用configuration-snippet注释,该注释将在location指令下添加一个配置。类似这样的代码应该可以:
nginx.ingress.kubernetes.io/configuration-snippet: |
try_files $uri $uri/ $uri/index.html /index.html; ✌️
发布于 2021-10-29 01:11:07
我们有一个非常类似的案例,gatsby static site on a GCP bucket。
我们还测试了try_files和index指令,但不起作用。
在我们的例子中,这些黑客configuration-snippets做到了这一点:
kind: Service
apiVersion: v1
metadata:
name: gcp-storage-bucket
spec:
type: ExternalName
externalName: storage.googleapis.com
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /<BUCKET_NAME>$uri
nginx.ingress.kubernetes.io/backend-protocol: "HTTPS"
nginx.ingress.kubernetes.io/upstream-vhost: "storage.googleapis.com"
nginx.ingress.kubernetes.io/configuration-snippet: |
if ($uri ~ "^/(.*)/$") {
rewrite ^(.+)/$ $1 last;
proxy_pass https://storage.googleapis.com;
}
if ($uri ~ "^\/$") {
rewrite ^ /<BUCKET_NAME>/index.html break;
proxy_pass https://storage.googleapis.com;
}
if ($uri !~ "^(.*)\.(.*)$") {
rewrite ^ /<BUCKET_NAME>$uri/index.html break;
proxy_pass https://storage.googleapis.com;
}
labels:
app.kubernetes.io/instance: static-site.example.com
name: static-site.example.com
namespace: default
spec:
rules:
- host: static-site.example.com
http:
paths:
- path: /(.*)
backend:
service:
name: gcp-storage-bucket
port:
number: 443
pathType: Prefix在我们的情况下,除了404之外,一切似乎都很正常。
也许有一种更有效的方法可以做到这一点,但希望这能有所帮助。
https://stackoverflow.com/questions/63333288
复制相似问题