我有一个问题,nginx似乎忽略(或覆盖)我在AWS Elastic Beanstalk上的Ubuntu Docker容器中的upped client_max_body_size指令 . 这会阻止用户上传任何大于nginx默认值1MB的文件 .
我使用了client_max_body_size 10M;在http,服务器和位置块无济于事,我仍然在nginx日志中看到"client intended to send too large body"错误 . 我已经在AWS EC2 Ubuntu实例上成功使用了这些设置,但由于在Docker容器中使用相同的设置,我遇到了这个问题 . 我也试过使用这里概述的ebextension Increasing client_max_body_size in Nginx conf on AWS Elastic Beanstalk
应用程序本身是在Tomcat容器中运行的CFML(Railo) .
以下是相关的nginx文件:
完整的未删节文件在这里https://github.com/chapmandu/docker-railo
提前致谢 .
nginx error.log
2014/12/02 03:02:05 [error] 32116#0: *142 client intended to send too large body: 1290803 bytes, client: 172.31.19.39, server: , request: "POST /listings/35602/images/create HTTP/1.1", host: "staging.svr.com.au", referrer: "http://staging.svr.com.au/listings/35602/images/new"
nginx.conf
daemon off;
worker_processes 1;
events {
worker_connections 1024;
}
http {
client_max_body_size 10M;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
include /etc/nginx/sites-enabled/default;
}
默认
server
{
listen 80;
server_name localhost;
client_max_body_size 10M;
# don't rewrite for static files
location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|pdf|txt|tar|wav|bmp|rtf|js|flv|swf|html|htm|map|ttf|woff)$
{
root /var/www;
}
location /
{
root /var/www;
index index.cfm;
client_max_body_size 10M;
include proxy_params;
}
}
proxy_params
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;
3 回答
事实证明,AWS使用nginx代理与docker容器的连接,因此需要更新AWS nginx配置以设置client_max_body_size . 请注意,我正在使用运行Docker 1.2.0的64位Amazon Linux 2014.09 v1.0.9 .
我需要使用下面的内容创建.ebextensions / 01-client-max-body.config .
重要的一行是“server 127.0.0.1:EB_CONFIG_NGINX_UPSTREAM_PORT;”
由超级有用的AWS支持提供的答案..
接受的答案对我不起作用,但我设法弄明白了 .
以前我使用了预构建的docker镜像(托管在我自己的注册表中),并在dockerrun.aws.json文件中指定了访问和url,然后在
.elasticbeanstalk/config.json
上有一个配置文件,其中包含以下内容:这仅将dockerrun文件上载为工件 .
为了通过ebextentions设置client_max_body_size,您 must 切换到通过
eb deploy
上传整个文件夹或指定包含.ebextentions文件夹的zip文件工件然后我在
.ebextentions/size.config
的配置文件中取得了成功,其中包含:感谢https://stackoverflow.com/a/23587371/2653503,https://stackoverflow.com/a/39829789/2653503和其他一些我现在找不到的答案,我得到了这个答案 .
在黑暗中有一些刺...我注意到你的例子中有2次出现的client_max_body_size参数,并且你的github配置是不同的 . 如果配置文件或include中出现多个指令,则nginx将采用最后定义的指令的值 .
另一种考虑的可能性是,通过Web表单上传的文件通常具有比文件系统中显示的文件大的文件大小 . 你有没有尝试过超大的设置,比如
client_max_body_size 500m;
参考:掌握Nginx