0%

Fix k8s 413 Request Entity Too Large WordPress Error

通过k8s配置wordpress后,上传大文件会出现“413 Request Entity Too Large”的错误。可通过下面方式修正

  1. 如果有外部nginx做转发,需要设置 client_body_max_size

    1
    2
    3
    http {
    client_max_body_size 0; # 设置为0代表不做限制
    }
  2. WordPress的Ingress也需要配置 client_max_body_size

    1
    2
    3
    4
    5
    6
    apiVersion: extensions/v1beta1
    kind: Ingress
    metadata:
    name: wp-ingress
    annotations:
    nginx.ingress.kubernetes.io/proxy-body-size: 512m
  3. 下载 Increase Maximum Upload File Size 插件/或配置uploads.ini

配置uploads.ini方式

① 创建uploads.ini

1
2
3
4
5
file_uploads = On
memory_limit = 512M
upload_max_filesize = 512M
post_max_size = 512M
max_execution_time = 3600

② 添加configMap配置

1
kubectl create configmap wp-uploads-ini --from-file uploads.ini

③ 映射到文件 /usr/local/etc/php/conf.d/uploads.ini

1
2
3
4
5
6
7
8
9
10
11
containers:
- image: wordpress:5.4.2-apache
...
volumeMounts:
- name: wp-config-uploads-ini
mountPath: /usr/local/etc/php/conf.d/uploads.ini
subPath: uploads.ini
volumes:
- name: wp-config-uploads-ini
configMap:
name: wp-uploads-ini