gpt4 book ai didi

php - Kubernetes Ingress NGINX for Laravel 通过 fast-cgi

转载 作者:行者123 更新时间:2023-12-04 13:31:14 27 4
gpt4 key购买 nike

我在我的 Kubernetes 集群中使用 Ingress NGINX:https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/
由于 Ingress NGINX 支持 Fast CGI 作为直接后端,我运行一个带有 Laravel 应用程序的容器,通过 php-fpm 在端口 9000 上提供服务。现在我尝试使用 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 的需求?

最佳答案

我想你的nginx配置的监听端口应该是9000。
我的猜测,你所拥有的是:

  • 一个带有 PHP 应用程序的容器,由 Nginx 在 9000 端口提供服务。
  • 服务端口 80 上的 ClusterIP 服务,映射到您的端口 9000 容器端口。
  • 那么您正在尝试使用入口向外界公开您的服务

  • 所以你需要下面的 k8 声明
  • 部署/Statefulset - 创建您的容器。
  • 服务 - 将您的服务端口 80 映射到容器端口 9000
  • Ingress - 在端口 80
  • 将您的服务暴露给外部工作

    这是一个例子(虽然我使用 ambassador ingress.class for minikube 但原理是一样的) https://github.com/francisfueconcillo/k8-geektalk/blob/master/wp-deployment.yaml

    关于php - Kubernetes Ingress NGINX for Laravel 通过 fast-cgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64937343/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com