cha*_*ndu 9 ubuntu nginx railo docker amazon-elastic-beanstalk
我有一个问题,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 在AWS Elastic Beanstalk上的Nginx conf中增加client_max_body_size
应用程序本身是在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"
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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;
Run Code Online (Sandbox Code Playgroud)
cha*_*ndu 10
事实证明,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;"
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)'
Run Code Online (Sandbox Code Playgroud)
由超级有用的AWS支持提供的答案..
Sam*_*ick 10
接受的答案对我不起作用,但我设法弄清楚了。
以前我使用了一个预构建的 docker 镜像(托管在我自己的注册表中),并在 dockerrun.aws.json 文件中指定了访问和 url,然后有一个配置文件.elasticbeanstalk/config.json如下:
deploy:
artifact: Dockerrun.aws.json
Run Code Online (Sandbox Code Playgroud)
这仅上传了 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"
Run Code Online (Sandbox Code Playgroud)
我来到这个答案感谢在/sf/answers/1651116001/,/sf/answers/2788085261/,和其他几个人,我现在无法找到。
| 归档时间: |
|
| 查看次数: |
4798 次 |
| 最近记录: |