我遇到了一个问题,其中nginx似乎忽略(或覆盖)我在AWS Elastic Beanstalk上的Ubuntu Docker容器中的upped client_max_body_size指令。这会阻止用户上传大于nginx默认值1MB的文件。
我使用了client_max_body_size 10M;在http,服务器和位置块无济于事,我仍然看到"客户端意图发送太大的身体" nginx日志中的错误。我已经在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
提前致谢。
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"
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_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;
答案 0 :(得分:10)
事实证明,AWS使用nginx代理与docker容器的连接,因此需要更新AWS nginx配置以设置client_max_body_size。请注意,我使用64位运行Docker 1.2.0的Amazon Linux 2014.09 v1.0.9。
我需要使用以下内容创建.ebextensions / 01-client-max-body.config。
重要的一行是“server 127.0.0.1:EB_CONFIG_NGINX_UPSTREAM_PORT;”
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)'
由超级有用的AWS支持提供的答案..
答案 1 :(得分:4)
接受的答案对我不起作用,但我设法弄明白了。
以前我使用了预构建的docker镜像(托管在我自己的注册表中),并在dockerrun.aws.json文件中指定了访问权限和url,然后在.elasticbeanstalk/config.json
处有一个配置文件,其中包含以下内容:
deploy:
artifact: Dockerrun.aws.json
这只将dockerrun文件上传为工件。
要通过ebextentions设置client_max_body_size,您必须切换到通过eb deploy
上传整个文件夹或指定包含.ebextentions文件夹的zip文件工件
然后我在.ebextentions/size.config
的配置文件中取得了成功,其中包含:
files:
/etc/nginx/conf.d/proxy.conf:
content: |
client_max_body_size 50M;
container_commands:
01_reload_nginx:
command: "service nginx reload"
由于https://stackoverflow.com/a/23587371/2653503,https://stackoverflow.com/a/39829789/2653503和其他一些我现在无法找到的其他人,我得到了这个答案。
答案 2 :(得分:1)
在黑暗中进行了一些攻击......我注意到你的示例中有2次出现client_max_body_size参数,并且你的github配置不同。如果配置文件或include中出现多个指令,则nginx将采用最后定义的指令的值。
另一种考虑的可能性是,通过Web表单上传的文件通常具有比文件系统中显示的文件大的文件大小。您是否尝试过超大设置,例如
client_max_body_size 500m;
参考:掌握Nginx
答案 3 :(得分:0)
这是我遇到的另一个选项,显然是内联修改了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