[英]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.