更改上传文件的大小
1. 413 Request Entity Too Large错误
当我们上传大于2m的时候就会出现这个错误。
解决办法:
1.1 修改nginx的配置文件
模块:client_max_body_size
https://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
语法:
Syntax: client_max_body_size size;
Default:
client_max_body_size 1m;
Context: http, server, location
所以修改配饰文件,加上:
client_max_body_size 50m;
server {
listen 80;
server_name blog.yq.com;
client_max_body_size 50m;
error_log /var/log/nginx/error_blog.log error;
location / {
root /html/blog;
index index.php index.html;
}
location ~ \.php$ {
root /html/blog;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
}
重启nginx在进行测试:
systemctl restart nginx
1.1.1 错误 500 Internal Server Error
修改好了上传的文件的大小之后,会出现500 Internal Server Error错误:
2021/09/19 11:51:25 [crit] 9291#9291: *1 open() "/var/lib/nginx/tmp/client_body/0000000001" failed (13: Permission denied), client: 192.168.246.1, server: blog.yq.com, request: "POST /wp-admin/update.php?action=upload-theme HTTP/1.1", host: "blog.yq.com", referrer: "http://blog.yq.com/wp-admin/theme-install.php?browse=popular"
是"/var/lib/nginx/tmp/client_body/0000000001" failed (13: Permission denied),目录的权限问题:
ll -d /var/lib/nginx/tmp
drwxrwx--- 7 nginx root 78 Jun 25 13:44 /var/lib/nginx/tmp
发现该目录的用户是nginx,而管理nginx我们设置的是www,所以修改目录权限即可
chown www.www -R /var/lib/nginx/
systemctl restart nginx
1.2 然后再进行上传
需要配置PHP的上传的文件大小超过php.ini文件中定义的upload_max_filesize值。
vim /etc/php.ini
/upload_max_filesize
upload_max_filesize = 10M
systemctl restart php-fpm