Ubuntu Nginx客户端\u最大\u体\u尺寸不适用于AWS Elastic Beanstalk上的Docker容器

Ubuntu Nginx客户端\u最大\u体\u尺寸不适用于AWS Elastic Beanstalk上的Docker容器,ubuntu,nginx,docker,amazon-elastic-beanstalk,railo,Ubuntu,Nginx,Docker,Amazon Elastic Beanstalk,Railo,在AWS Elastic Beanstalk上的Ubuntu Docker容器中,我遇到了一个nginx似乎忽略(或覆盖)了我的Upper client_max_body_size指令的问题。这会阻止用户上传大于nginx默认1MB的文件 我已经使用了10米大小的客户_max_body_;在http、server和location块中,我仍然在nginx日志中看到“client打算发送太大的body”错误。我已经在AWS EC2 Ubuntu实例上成功地使用了这些设置,但是由于在Docker容器

在AWS Elastic Beanstalk上的Ubuntu Docker容器中,我遇到了一个nginx似乎忽略(或覆盖)了我的Upper client_max_body_size指令的问题。这会阻止用户上传大于nginx默认1MB的文件

我已经使用了10米大小的客户_max_body_;在http、server和location块中,我仍然在nginx日志中看到“client打算发送太大的body”错误。我已经在AWS EC2 Ubuntu实例上成功地使用了这些设置,但是由于在Docker容器中使用了相同的设置,我遇到了这个问题。我也尝试过使用这里概述的ebextension

应用程序本身是在Tomcat容器中运行的CFML(Railo)

以下是相关的nginx文件:

完整的未桥接文件在这里

提前谢谢

nginx error.log nginx.conf 违约 代理参数
黑暗中的几次刺杀。。。我注意到在您的示例中出现了两个client_max_body_size参数,并且您的github配置不同。如果在配置文件或include中有多个指令出现,nginx将采用最后定义的指令的值

另一个可能考虑的是,通过Web窗体上传的文件通常比文件系统中显示的文件大。您是否尝试过超大的设置,例如

客户最大身体尺寸500m


参考:掌握Nginx

事实证明,AWS使用Nginx代理与docker容器的连接,有必要更新AWS Nginx配置,以设置客户端的最大大小。请注意,我使用的是运行Docker 1.2.0的64位Amazon Linux 2014.09 v1.0.9

我需要使用下面的内容创建.ebextensions/01-client-max-body.config

重要的一行是“服务器127.0.0.1:EB\u配置\u NGINX\u上游\u端口


超级有用的AWS支持提供的答案。

接受的答案对我不起作用,但我设法找到了答案

之前,我使用了一个预构建的docker映像(托管在我自己的注册表中),并在dockerrun.aws.json文件中指定了访问权限和url,然后在
.elasticbeanstalk/config.json
上有一个配置文件,其中包含以下内容:

deploy:
  artifact: Dockerrun.aws.json
这仅将dockerrun文件作为工件上载

为了通过eExtensions设置客户端的最大体大小,您必须切换到通过eb deploy上传整个文件夹,或者指定包含.ebExtensions文件夹的zip文件工件

然后,我成功地在
.ebextensions/size.config
上使用了一个配置文件,其中包含:

files:
  /etc/nginx/conf.d/proxy.conf:
    content: |
      client_max_body_size 50M;
container_commands:
   01_reload_nginx:
     command: "service nginx reload"

我得到了这个答案,多亏了,还有一些我现在找不到的其他答案。

这里是我遇到的另一个选项,显然是修改nginx.conf内联:创建这个ebextensions文件:

commands:
  01_filesize:
    cwd: /etc/nginx
    test: "! grep client_max_body_size nginx.conf"
    command: sed -i -e 's/http {/http {\n    client_max_body_size 0;\n/' nginx.conf
  02_filesize:
    cwd: /etc/nginx/sites-available
    test: "! grep client_max_body_size elasticbeanstalk-nginx-docker-proxy.conf"
    command: sed -i -e 's/server {/server {\n        client_max_body_size 0;\n/'  elasticbeanstalk-nginx-docker-proxy.conf;sed -i -e 's/location \/ {/location \/ {\n            client_max_body_size 0;\n/' elasticbeanstalk-nginx-docker-proxy.conf

我已经尝试了client\u max\u body\u size指令的所有组合。上面贴的只是最近的一个。我目前有10mb的限制,但我不能上传任何超过1000kb的内容(甚至是稍微超过1000kb)。我真的不想将限制提高到500米,因为我实际上想将上传限制到10米。不确定它是否也适用于docker环境,但解决方案更简单,它只是在conf.d目录中添加了另一个文件:Cheers,我发布的解决方案是针对docker 1.2的。我从AWS Support for Docker 1.3+收到的解决方案与您的链接几乎完全相同。我发现nginx配置与上面报告的配置有很大不同,重置整个上游代理似乎是一种过激行为(另外,它已经在
/etc/nginx/conf.d/elasticbeanstalk nginx Docker upstream.conf
中定义)如果只是用来增加客户的体型。这个答案:应该做这个技巧这是我用docker on Elastic Beanstalk让它工作的唯一方法。我尝试了这个,但它仍然没有为我解决这个问题。。。。。我的想法快用完了为了澄清这一点,您所要做的就是将.ebextensions文件夹与dockerrun json文件一起包含在源代码包zip中。然后您仍然可以像以前一样使用预构建的docker映像。
proxy_redirect off;

# # If you want your server to identify itself only as Tomcat you can pass
# # the Tomcat setting to Nginx telling Nginx not to change it
#proxy_pass_header Server;

# Point Nginx to Tomcat
proxy_pass  http://localhost:8080;

# Send appropriate headers through
# Forward the real ip to Tomcat (and Railo)

proxy_buffers 16 16k;
proxy_buffer_size 32k;

# prevent regular 504 Gateway Time-out message
proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;

# pass headers through
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Query-String $request_uri;
proxy_set_header X-Host $host;
proxy_set_header X-Remote-Addr $remote_addr;
proxy_set_header X-Request-Filename $request_filename;
proxy_set_header X-Request-URI $request_uri;
proxy_set_header X-Server-Name $server_name;
proxy_set_header X-Server-Port $server_port;
proxy_set_header X-Server-Protocol $server_protocol;

proxy_intercept_errors on;

# apparently this is how to disable cache?
expires     -1;
files:
  "/tmp/custom-nginx.conf":
    mode: "00644"
    owner: "root"
    group: "root"
    content: |
      upstream docker {
        server 127.0.0.1:EB_CONFIG_NGINX_UPSTREAM_PORT;
        keepalive 256;
      }

      server {
        listen EB_CONFIG_HTTP_PORT;
        client_max_body_size 10M;

        location / {
          proxy_pass      http://docker;
          proxy_http_version      1.1;
          proxy_set_header Host                $host;
          proxy_set_header X-Real-IP           $remote_addr;
          proxy_set_header X-Forwarded-For     $proxy_add_x_forwarded_for;
        }
      }

container_commands:
  01_remove_orig_config:
    command: 'sed -i ''/EOF/,/EOF/d'' /opt/elasticbeanstalk/hooks/appdeploy/enact/00flip.sh '
  02_add_new_conf:
    command: 'sed -i ''/# set up nginx/a sed -i s\/EB_CONFIG_NGINX_UPSTREAM_PORT\/$EB_CONFIG_NGINX_UPSTREAM_PORT\/ \/tmp\/custom-nginx.conf \nsed -i s\/EB_CONFIG_HTTP_PORT\/$EB_CONFIG_HTTP_PORT\/ \/tmp\/custom-nginx.conf \ncat \/tmp\/custom-nginx.conf > \/etc\/nginx\/sites-available\/elasticbeanstalk-nginx-docker.conf'' /opt/elasticbeanstalk/hooks/appdeploy/enact/00flip.sh'
    test: 'test ! $(grep custom-nginx.conf /opt/elasticbeanstalk/hooks/appdeploy/enact/00flip.sh)'
deploy:
  artifact: Dockerrun.aws.json
files:
  /etc/nginx/conf.d/proxy.conf:
    content: |
      client_max_body_size 50M;
container_commands:
   01_reload_nginx:
     command: "service nginx reload"
commands:
  01_filesize:
    cwd: /etc/nginx
    test: "! grep client_max_body_size nginx.conf"
    command: sed -i -e 's/http {/http {\n    client_max_body_size 0;\n/' nginx.conf
  02_filesize:
    cwd: /etc/nginx/sites-available
    test: "! grep client_max_body_size elasticbeanstalk-nginx-docker-proxy.conf"
    command: sed -i -e 's/server {/server {\n        client_max_body_size 0;\n/'  elasticbeanstalk-nginx-docker-proxy.conf;sed -i -e 's/location \/ {/location \/ {\n            client_max_body_size 0;\n/' elasticbeanstalk-nginx-docker-proxy.conf