zoukankan      html  css  js  c++  java
  • 影响 POST 请求文件上传失败的几个环节的配置(php + nginx)

    写在前面

    最近写一个 php 接口,接受上传的文件,发现文件只要超过 5m 以上就会无响应失败,最后发现是 shadowsocks 的 timeout 设置问题(我全程开了全局的 VPN),但一开始并不知晓,把 nginx 和 php 的相关配置都改了个遍。

    接着这回,我干脆记录一下,以后遇到此类问题可以按照这个逻辑顺序去排查。

    零、环境

    PHP Version 7.0.10

    一、php

    通过修改 php.ini

    更多的配置参考:http://php.net/manual/en/ini.core.php

    1、上传相关

    options type desc remark
    file_uploads boolean 是否允许 HTTP 文件上传 'On' or 'Off'
    upload_tmp_dir string 上传时存储文件的临时目录 如果未指定,将使用系统的默认值(/tmp)
    upload_max_filesize integer 上传文件的最大大小 是所有文件字段的大小总和
    post_max_size integer post_max_size = upload_max_filesize + 所有其他字段的长度(跟文件比微不足道) post_max_size 一般略大于upload_max_filesize,但为了省事可以直接让它们相等
    max_file_uploads integer 允许同时上传的最大文件数。(提交时保留空白的上传字段不计入此限制)

    注:upload_max_filesizepost_max_size 可以用速记表达:K (for Kilobytes), M (for Megabytes) and G (for Gigabytes; available since PHP 5.1.0) ,不区分大小写。

    2、时间相关

    options type desc remark
    max_input_time integer 脚本解析输入数据允许的最大时间,单位是秒。 它从接收所有数据到开始执行脚本进行测量的
    max_execution_time integer 这设置了脚本被解析器中止之前允许的最大执行时间,单位秒。 这有助于防止写得不好的脚本占尽服务器资源 你的 web 服务器也可以有其他超时设置

    max_input_timemax_execution_time

    3、内存相关

    options type desc remark
    memory_limit integer 这将设置允许脚本分配的最大内存量(以字节为单位)。这有助于防止编写糟糕的脚本占用服务器上的所有可用内存 要没有内存限制,请将此指令设置为 -1

    二、nginx

    通过修改 nginx.conf

    options type desc remark
    client_max_body_size integer

    返回 413(请求实体太大)错误。

    三、shadowsocks

    通过修改 preferences

    options type desc remark
    timeout integer 超时时间

    返回 net::ERR_CONNECTION_RESET 错误。

  • 相关阅读:
    使用go-fuse开发一个fuse 文件系统
    awesome-fuse-fs
    jdk 容器运行环境指定时区
    几个不错的golang工具包
    golang 一些不错的log 包
    mysql_fdw 集成go-mysql-server 开发的mysql server
    一些不错的golang web 框架
    golang gomail+fasttemplate+mailhog 发送邮件
    golang go-simple-mail+fasttemplate+mailhog 发送邮件
    实现一个简单的golang db driver
  • 原文地址:https://www.cnblogs.com/xjnotxj/p/9953882.html
Copyright © 2011-2022 走看看