SweetEriri

Django后台传送长字符串后报500错误

前几天写新文档的时候通过后台上传文章后会直接报500错误导致文章无法保存

在开发环境上传文章就一切良好 可以确定不是代码的问题

既然不是代码的问题 就是线上环境和开发环境启动方式不同导致的

开发环境是直接通过manager.py文件启动 服务器上加了一层nginx代理 既然如此 就去查看nginx的的错误日志即可

2020/07/28 16:35:00 [crit] 12608#0: *65709 open() "/var/lib/nginx/tmp/client_body/0000000004" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:35:12 [crit] 12608#0: *65704 open() "/var/lib/nginx/tmp/client_body/0000000005" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:35:29 [crit] 12608#0: *65705 open() "/var/lib/nginx/tmp/client_body/0000000006" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:36:55 [crit] 12608#0: *65717 open() "/var/lib/nginx/tmp/client_body/0000000007" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:39:47 [crit] 12608#0: *65734 open() "/var/lib/nginx/tmp/client_body/0000000008" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:39:59 [crit] 12608#0: *65736 open() "/var/lib/nginx/tmp/client_body/0000000009" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:41:33 [crit] 12608#0: *65743 open() "/var/lib/nginx/tmp/client_body/0000000010" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:42:29 [crit] 12608#0: *65747 open() "/var/lib/nginx/tmp/client_body/0000000011" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:43:10 [crit] 12608#0: *65766 open() "/var/lib/nginx/tmp/client_body/0000000012" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:43:15 [crit] 12608#0: *65769 open() "/var/lib/nginx/tmp/client_body/0000000013" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:43:23 [crit] 12608#0: *65775 open() "/var/lib/nginx/tmp/client_body/0000000014" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:43:48 [crit] 12608#0: *65777 open() "/var/lib/nginx/tmp/client_body/0000000015" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:45:01 [crit] 12608#0: *65782 open() "/var/lib/nginx/tmp/client_body/0000000016" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:51:23 [crit] 12608#0: *65790 open() "/var/lib/nginx/tmp/client_body/0000000017" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:56:00 [crit] 12608#0: *65794 open() "/var/lib/nginx/tmp/client_body/0000000018" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/6/change/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/6/change/"
2020/07/28 16:56:45 [crit] 12608#0: *65795 open() "/var/lib/nginx/tmp/client_body/0000000019" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"
2020/07/28 16:57:00 [crit] 12608#0: *65798 open() "/var/lib/nginx/tmp/client_body/0000000020" failed (13: Permission denied), client:  , server: sweeteriri.com, request: "POST /admin/blog/post/add/ HTTP/1.1", host: "sweeteriri.com", referrer: "https://sweeteriri.com/admin/blog/post/add/"

通过日志可以看到open() "/var/lib/nginx/tmp/client_body/0000000015" failed (13: Permission denied) 这句是解决问题的关键

通过查看/var/lib/nginx/tmp下面的文件权限发现 是用户和组为root导致的 修改文件夹权限后再次上传长文章即可解决问题

chown -R $nginx设置的用户:$nginx设置的用户 /var/lib/nginx/tmp/*

但是为什么会出现短的文章可以上传 长的文章不可以上传呢?

感觉是nginx配置文件的问题 通过查看nginx配置文件发现 client_body_buffer_size 这个值没有被设定 而默认值为8k/16k

于是问题就这么解决了

nginx是把小于设置buffer大小的内容缓冲进内存,大于设置的 需要放到服务器的一个临时目录 这个临时目录就是/var/lib/nginx/tmp

所以解决这个问题可以通过修改权限或者增大client_body_buffer_size的值来解决上传数据后返回500


发表评论

评论列表,共 1 条评论

  • Looking for serious relationship that will lead to marriage https://katty.page.link/xBau
    Hi! If you want to pull me on your stick, then message me where we can meet. Message there https://allinna.page.link/jrKj