假設我在 Docker 容器中有一個 php-fpm 程式(例如bitnami/bitnami-docker-php-fpm),并且我不想使用 Nginx 容器,我如何使用安裝在 Docker 之外的 Nginx 來代理它?
uj5u.com熱心網友回復:
例如,如果您運行的是Nginx的入口控制器或一個特定容器的Nginx
莢
apiVersion: v1
kind: Pod
metadata:
name: example-app
labels:
app: example-app
spec:
containers:
- name: example-app
image: example-app:1.0
ports:
- containerPort: 9000
name: fastcgi
服務
apiVersion: v1
kind: Service
metadata:
name: example-service
spec:
selector:
app: example-app
ports:
- port: 9000
targetPort: 9000
name: fastcgi
入口
apiVersion: v1
kind: ConfigMap
metadata:
name: example-cm
data:
SCRIPT_FILENAME: "/example/index.php"
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: "nginx"
nginx.ingress.kubernetes.io/backend-protocol: "FCGI"
nginx.ingress.kubernetes.io/fastcgi-index: "index.php"
nginx.ingress.kubernetes.io/fastcgi-params-configmap: "example-cm"
name: example-app
spec:
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
name: fastcgi
參考檔案:https : //kubernetes.github.io/ingress-nginx/user-guide/fcgi-services/
如果您的 Nginx 在 docker 之外運行,您可以使用主機 IP
server {
listen 80;
server_name localhost;
root /var/www/test;
error_log /var/log/nginx/localhost.error.log;
access_log /var/log/nginx/localhost.access.log;
location / {
# try to serve file directly, fallback to app.php
try_files $uri /index.php$is_args$args;
}
location ~ ^/. \.php(/|$) {
fastcgi_pass 192.168.59.103:9000;
fastcgi_split_path_info ^(. \.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/352474.html
上一篇:Nginx代理https到http-routines:ssl3_get_record:wrongversionnumber
