![](/img/trans.png)
[英]How can I set a kubernetes pod so php-fpm and nginx can manipulate data on a persistent volume?
[英]Nginx, FPM in kubernetes pod - css are not rendered
我在一個 pod 中將 FPM 和 nginx 作為兩個容器運行。 我的應用程序正在運行,我可以訪問它,但瀏覽器不呈現 CSS 文件。 控制台中沒有錯誤。 我的部署文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
labels:
app: test
spec:
replicas: 1
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
volumes:
- name: shared-files
emptyDir: {}
- name: nginx-config-volume
configMap:
name: test
containers:
- image: test-php
name: app
ports:
- containerPort: 9000
protocol: TCP
volumeMounts:
- name: shared-files
mountPath: /var/appfiles
lifecycle:
postStart:
exec:
command: ['sh', '-c', 'cp -r /var/www/* /var/appfiles']
- image: nginx
name: nginx
ports:
- containerPort: 80
protocol: TCP
volumeMounts:
- name: shared-files
mountPath: /var/appfiles
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
Nginx 配置:
events {
}
http {
server {
listen 80;
root /var/appfiles/;
index index.php index.html index.htm;
# Logs
access_log /var/log/nginx/tcc-webapp-access.log;
error_log /var/log/nginx/tcc-webapp-error.log;
location / {
# try_files $uri $uri/ =404;
# try_files $uri $uri/ /index.php?q=$uri&$args;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
我可以在瀏覽器中打開頁面,我可以看到所有組件、鏈接、按鈕等,但頁面未呈現,看起來 css 未加載。
為了解決您的問題,請將configMap
更改為它的確切名稱nginx-configmap
並且在您的configMap nginx 配置文件中可以如下所示:
apiVersion: v1
kind: ConfigMap
metadata:
name: "nginx-configmap"
data:
nginx.conf: |
server {
listen 80;
server_name _;
charset utf-8;
root /var/appfiles/;
access_log /var/log/nginx/tcc-webapp-access.log;
error_log /var/log/nginx/tcc-webapp-error.log;
location / {
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
您可以找到對您有用的中型文章。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.