【问题标题】:Nginx - Can't Upload file larger than 10KbNginx - 无法上传大于 10Kb 的文件
【发布时间】:2019-03-22 09:10:51
【问题描述】:

我使用在我的本地主机上完美运行的 AJAX 代码构建了一个文件上传表单。

但是,当我将此代码上传到我的 nginx 服务器时。尝试上传任何大于 10KB 的文件(是的,这是一个 K)时,我得到一个 net::ERR_CONNECTION_RESET。我正在使用 HTTPS。

下面是我的 ajax 代码:

$("#save-button").click(function(){
    console.log("max_execution_time = <?php echo(ini_get('max_execution_time')); ?>");
    console.log("max_input_time = <?php echo ini_get('max_input_time'); ?>");
    console.log("memory_limit = <?php echo ini_get('memory_limit'); ?>");
    console.log("post_max_size = <?php echo ini_get('post_max_size'); ?>");
    console.log("file_uploads = <?php echo ini_get('file_uploads'); ?>");
    console.log("upload_max_filesize = <?php echo ini_get('upload_max_filesize'); ?>");
    console.log("max_file_uploads = <?php echo ini_get('max_file_uploads'); ?>");
    console.log("default_socket_timeout = <?php echo ini_get('default_socket_timeout'); ?>");

    var formData = new FormData();

    var formRawData = $('#info-form-container').serializeArray();

    formRawData.forEach(function(element) {
        if(element.value!=""){
            formData.append(element.name, element.value);
        }
    });

    formData.append('data[ID]',id);
    formData.append('data[FLAG]', myData.CURRENT_FLAG)
    if (myData.CURRENT_FLAG == 1 || myData.CURRENT_FLAG == 6) {
        console.log($("#file")[0].files[0])
        formData.append('FILE', $("#file").prop('files')[0])
    }

    var xhr = new XMLHttpRequest();

    xhr.open('POST', '/mrk/Csr_mkt/save/', true);

    var onerror = function(event) {
        toastr.error("Error");
    }

    xhr.onload = function () {
        if (xhr.status === 200) {
            response = JSON.parse(xhr.responseText);

            if(response.errorId == 0) {
                notifsuccess(response.message);
            } else {
                swal('', response.message, 'error')
            }
        }
    };

    xhr.send(formData);

    return false;
});

结果 以下是我的浏览器控制台的结果:

NGinx 会议 下面是我的 nginx 配置:

#NGINX CodeIgniter CONFIG
#=========================================================
#
# The default server
#
server {
    listen 80 default_server;
#   listen [::]:80 default_server;
#   listen 443 https;
    client_max_body_size 100M;
#    ssl on;
#    ssl_certificate /etc/ssl/certs/ca-bundle.crt;
#    ssl_certificate_key /etc/ssl/privatekey3.key;


    server_name mydomain.id www.mydomain.id;
#   server_name mydomain.id www.mydomain.id localhost;
#   return 301 https://ganeshaoperation.id$request_uri;
#   rewrite ^/(.+) https://mydomain.id/$1 permanent;
        root  /var/www/html/go-erp;
#       dev02 /var/www/html/go-erp;
        index  index.php index.htm index.html;
    #charset koi8-r;

    access_log  /var/log/nginx/appsvr1_acces.log  main;
    error_log  /var/log/nginx/appsvr1_error.log;

    location / {
        #try_files $uri $uri/ /index.php;
        try_files $uri $uri/ /index.php?$uri; # CI

        }

   location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
        expires max;
        log_not_found off;
    }

 # redirect server error pages to the static page /50x.html
 #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    location  /pmd {
        auth_basic "Admin Login";
        auth_basic_user_file /etc/nginx/pma_pass;
        index index.php;
    }

  location ~ \.php$ {
    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    include /etc/nginx/fastcgi_params;
    fastcgi_read_timeout 150;
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_pass 127.0.0.1:80;
    #fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    #fastcgi_param HTTP_PROXY "";
  }

  location /uploads/ {
    internal;
    alias /var/www/html/go.erp_ori/uploads/;
    try_files $uri /$uri none.png / none.png;
        client_max_body_size 100M;
  }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny  all;
    }
}

请帮帮我,非常感谢

【问题讨论】:

  • https 的 nginx 配置在哪里?
  • 感谢您的帮助。但是这个问题已经解决了。存在导致此问题的错误代理配置

标签: php nginx file-upload upload


【解决方案1】:

请尝试在server, http or location 上下文中的 nginx conf 文件中添加以下行:

client_max_body_size 1024m;

记得重新加载或重启你的 nginx。

【讨论】:

  • 我已尝试编辑该文件。但重启 nginx 时出现错误:“nginx.service 的作业失败,因为控制进程退出并显示错误代码。请参阅'systemctl status nginx'
  • 查看我的帖子。我已经在我的帖子中添加了我的 nginx conf
【解决方案2】:

确保服务器端允许的最大上传大小。如果是这种情况,请增加该值。

https://www.tecmint.com/limit-file-upload-size-in-nginx/

【讨论】:

  • 我已尝试编辑该文件。但重启 nginx 时出现错误:“nginx.service 的作业失败,因为控制进程退出并显示错误代码。请参阅'systemctl status nginx'
  • 查看我的帖子。我已经在我的帖子中添加了我的 nginx conf
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-06
  • 2018-08-27
  • 2018-08-02
  • 1970-01-01
相关资源
最近更新 更多