【发布时间】:2021-03-04 08:00:57
【问题描述】:
我在我的 Kubernetes 集群中使用 Ingress NGINX:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/
由于 Ingress NGINX 支持 Fast CGI 作为直接后端,我在端口 9000 上运行了一个 Laravel 应用程序通过 php-fpm 服务的容器。现在我尝试使用 Ingress NGINX 作为代理,FCGI 作为后端,但我无法配置它。
根据 Laravel 文档,一个 nginx 配置应该如下所示(https://laravel.com/docs/8.x/deployment):
server {
listen 80;
server_name example.com;
root /srv/example.com/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
不幸的是,似乎无法为/ 和~ \.php$ 创建位置,因为 Ingress NGINX 确实无缘无故地保留了位置 /。
我的配置如下:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ingress-fastcgi
namespace: default
annotations:
kubernetes.io/ingress.class: "nginx"
kubernetes.io/ingress.allow-http: "false"
cert-manager.io/cluster-issuer: "letsencrypt-production"
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
nginx.ingress.kubernetes.io/backend-protocol: "FCGI"
nginx.ingress.kubernetes.io/fastcgi-index: "index.php"
spec:
tls:
- hosts:
- api.abcxyz.cloud
secretName: api-cert-secret
rules:
- host: api.abcxyz.cloud
http:
paths:
- path: /
backend:
serviceName: laravel
servicePort: 9000
如何使用 Ingress NGINX 和 FCGI 处理来自 Laravel 的需求?
【问题讨论】:
标签: php nginx kubernetes kubernetes-ingress nginx-ingress