【问题标题】:Nginx: Unable to upload file > 10MB. Client intended to send too large body [closed]Nginx:无法上传大于 10MB 的文件。客户打算发送太大的正文[关闭]
【发布时间】:2014-05-09 01:03:43
【问题描述】:

我在 Ubuntu 12.04 中使用 nginxunicorn 部署了我的 Rails 应用程序。

在我的应用程序中,我无法上传大小超过 10MB 的文件。我检查了nginx错误日志,发现

client intended to send too large body

我用谷歌搜索了一个解决方案,我必须将client_max_body_size 25M; 添加到/etc/nginx/nginx.conf。我这样做了,但它不起作用。请帮忙。下面添加nginx.conf内容:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events { worker_connections 1024; }

http {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    server_tokens off;
    client_max_body_size 25M;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";
    gzip_types text/plain text/xml text/css text/comma-separated-values;
        upstream app_server { server 127.0.0.1:8080 fail_timeout=0;}

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

【问题讨论】:

  • 这个问题似乎属于 Stack Exchange 网络中的另一个站点,因为它与编程无关。也许Super UserServer Fault

标签: ruby-on-rails nginx unicorn


【解决方案1】:

nginx.conf 中在服务器块中添加这一行:--

http {
 #other configuration
 server {
    #other configuration
    client_max_body_size 25M;
 }
}

http 块 中添加:--

server {
listen 80;
    client_max_body_size 25M;
    server_name localurl.me;

    index index.html index.htm;

    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_redirect off;
            proxy_pass http://0.0.0.0:3000;
    }
}

【讨论】:

  • 感谢您的回答。好的,这个服务器上下文中的其他配置是什么?
  • 其他配置意味着它在两个块中已经有一些其他设置应该保持原样,或者您可以相应地自定义。
  • 但我的 nginx.conf 没有任何 server 上下文。我该怎么办,请帮忙。
猜你喜欢
  • 2021-04-20
  • 2017-11-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 2021-10-28
  • 2010-10-06
相关资源
最近更新 更多