413 Request Entity Too Large in Nginx and Amazon ElasticBeanstalk - amazon-web-services

There are a lot of answers to this problem (question 1 question 2) but this solution that should work, doesn't work for me:
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 50M;
I have checked the status and contents of this created file via ssh and its correct. I also have tried other values and restarted the server multiple times.
client_max_body_size 0;
or
http {
client_max_body_size 50M;
}
This values do not work either.
it just wont work, even with "just" a 6mb image. it work with smaller images around size of 0.5mb. It's a RoR app with "64bit Amazon Linux 2018.03 v2.8.0 running Ruby 2.5 (Puma)". The instance size is t2.micro.

Try this. It worked for me:
content: |
server {
***your server configuration***
location / {
client_max_body_size 100M;
}
}

Related

How to increase file upload size in Django application running on EC2 instance with Nginx as revese Proxy?

I've a Django application that is running on EC2 instance. It is uploading file upto 100MB without any problems, but above 100MB file size, it gives error 413 Request Entity Too Large.
I've tried in file /etc/nginx/sites-available/default under server configuration.
client_max_body_size 10G;
I've also applied the same configuration in my domain configuration files, but all in vein. This configuration works well in my other servers, where I am running php applications.
Note: I've used gunicorn with supervisor for running Django application.
The client_max_body_size has to be defined in both http and https as stated in this answer.
So your nginx.conf file under /etc/nginx/sites-available/default would look something like:
http {
server {
...
listen 80;
server_name xxxx.net;
client_max_body_size 10G;
}
server {
...
listen 443 default_server ssl;
server_name xxxx.net;
client_max_body_size 10G;
}
}
#Helge thanks, I've applied the configuration parameters in both of them.
The issue is resolved now. The issue was, initially it was throwing error due to configuration parameter defined below other parameters, after resolving that Cloudflare started throwing 413 error. So, my team lead made configuration changes for the same.
in you 01__django.config add
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 20M;
#use These
or go to the your root via ssh
pass the commands
cd ..
cd ..
now use :
sudo nano /etc/nginx/nginx.conf
add :
client_max_body_size 20M; # these will add 20mb of size to your request body
Now Reload Your NGINX Server
using nginx -s restart

client intended to send too large body EB Nginx

I'm trying to increase the size of uploadable files to the server. However it seems there's a cap that prevents anything over 1MB of being uploaded.
I've read a lot of answers and none have worked for me.
I've done everything in this question
Stackoverflow question
I did everything here as well.
AWS resource
Here's what I have as the full error
2021/01/15 05:08:35 [error] 24140#0: *150 client intended to send too large body: 2695262 bytes, client: [ip-address-removed], server: , request: "PATCH /user HTTP/1.1", host: "host.domain.com", referrer: "host.domain.com"
I've made a file in this directory (which is at the root of my source code)
.ebextensions/nginx/conf.d/myconf.conf
In it I have
client_max_body_size 40M;
I know that EB is acknowledging it because if there's an error it won't deploy it.
Other than that I have no idea what to do
Does anybody know what might be the issue here?
Edit: backend is nodejs v12
Edit: Also tried this inside of a .conf file in .ebextensions
files:
"/etc/nginx/conf.d/myconf.conf":
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 20M;
Update:
Beanstalk on Amazon Linux 2 AMI has a little different path for NGINX config extensions:
.platform/nginx/conf.d
There you can place NGINX config extension files with *.conf extension, for example:
.platform/nginx/conf.d/upload_size.conf:
client_max_body_size 20M;
Documentation for this is here.
Original answer:
Nginx normally does not read config from where is serves the content. By default all config nginx read is /etc/nginx/nginx.conf and this file includes other files from /etc/nginx/conf.d/ with *.conf extension.
You need to place client_max_body_size 40M; there.

Access-Control-Allow-Origin cors error happening on NodeJS or Nginx

First at all, I have researched about the topic after writing the question, there are many similar question but I think the problem here is different:
No 'Access-Control-Allow-Origin' - Node / Apache Port Issue
We are getting this Access-Control-Allow-Origin cors error just when we send a heavy request:
Access to XMLHttpRequest at 'https://backend.*****.es/xxxxxx' from
origin 'https://www.testing.*******.es' has been blocked by CORS
policy: No 'Access-Control-Allow-Origin' header is present on the
requested resource
The rest of the request are working fine, I tried setting:
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
next();
});
but I got the same error.
I am starting to think it can be related with nginx.
This is the architecture we are using:
NodeJs, Expressjs
Middlewares:
const LIMIT = '100mb';
const global = () => [
morganMiddleware(),
compression(),
cors(),
bodyParser.urlencoded({ extended: true, limit: LIMIT }),
bodyParser.json({ limit: LIMIT }),
helmet(),
];
Server: Nginx 12.14.1
Host in AWS Elastic BeanStalk
Let me know if anyone have any clue what can be happening because I do not know if it is coming from our nodejs server, or nginx. We have tested many solutions and are still checking out other options.
Locate the type of Amazon Linux 2 (AL2) on your Elastic Beanstalk Dashboard:
Create the following directory structure from the root directory of your App:
.platform/nginx/conf.d/
Create the following file:
.platform/nginx/conf.d/01_custom_ngix.conf
Add client_max_body_size and change the value on the following inside your 01_custom_ngix.conf file you created (the example here is 1000M = 1GB) and make sure your AWS Instance Types is large enough t2.medium:
client_max_body_size 1000M;
client_body_buffer_size 100M;
...
...
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
Git Commit your changes.
Deploy your code:
> eb deploy
options: eb deploy --verbose --debug
We are getting this error in our sever:
2020/02/20 10:56:00 [error] 2784#0: *127 client intended to send too
large body: 4487648 bytes, client: 172.31.3.222, server: , request:
"PUT /cars/drafts/f7124841-f72c-4133-b49e-d9f709b4cf4d HTTP/1.1",
host: "backend.xxxxx.es", referrer:
"https://www.testing.xxxx.es/sellcar/photos/f7124841-f72c-4133-b49e-d9f709b4cf4d"
So besides the error that appears in the front is Access-Control-Allow-Origin it is related with the a limit set in NGINX.
Now we just need to figure out how to access to our elastic beanstalk instance to change that variables and that is already solved.
SSH to Elastic Beanstalk instance
To solve it, create a file x.config inside .ebextensions and change this variables with the next yaml file:
files:
"/etc/nginx/conf.d/01-client_max_body_size.conf":
mode: 000644
owner: root
group: root
content: |
# MODIFIED VARIABLES ADDED BY 01-client_max_body_size.conf
client_max_body_size 12m;
client_body_buffer_size 16k;
container_commands:
nginx_reload:
command: sudo service nginx reload
Then redeploy you environment.
Thank you very much all for your help!

How to customize nginx config on Node.js Elastic Beanstalk

I'm new to AWS EBS. I'm trying to modify etc/nginx/nginx.conf. I just wanted to add a line in http{ underscores_in_headers on; } and I'm able to change by accessing the instance with IP using putty. But the problem is that when auto scaling scales the environment with new IP then the line http{ underscores_in_headers on; } will be removed from new instance.
So, I want when server deploy new snapshot/instance has to be similar as the main server or you can say with same configuration.
I tried to solve my issue with this link
Step 1
To edit the configuration in AWS ElasticBean of nginx you need to add the configuration file in .ebextensions
to this add folder .ebextensions/nginx/ create proxy.config file
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
underscores_in_headers on;
it will start accepting header with underscores.
Step 2
In case if it not accepting header with underscores then access your instance with ssh and run the following command.
sudo service nginx reload
Hope it helps.
stack isn't letting me comment because I'm a noobie. Prateek really helped out, just one small modification to his solution for the proxy.config file and it should work! Don't forget to indent /etc/nginx/conf.d/proxy.conf: as well! Further info here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/nodejs-platform-proxy.html
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
underscores_in_headers on;

How can I increase the client_max_body_size in Elastic Beanstalk

I am using Golang with elastic Beanstalk and I find that I am able to upload files up to 1 MB and the ones bigger than that fail with the error client intended to send too large body: 1749956 bytes the bytes obviously depend on the file size . I have been reading this post Increasing client_max_body_size in Nginx conf on AWS Elastic Beanstalk and I changed my code created a file 01_nginx.config under the ebExtensions and put the following in it and I try to upload a video of 3 MB and it still gives that error, any suggestions ? I am new to this
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 20M;
I have tried all .ebextensions method of adding implementation level configuration for rails and it didn't help me in the latest Amazon Linux AMI. For the latest Amazon Linux AMI You need to follow this structure to increase the upload size. You need to follow this structure to increase the upload size limit.
Add the below folder setup in the root level of your project folder.
Folder structure (.platform/nginx/conf.d/proxy.conf)
.platform/
nginx/
conf.d/
proxy.conf
Add this line to proxy.conf (Inside .platform/nginx/conf.d/ folder)
client_max_body_size 50M;
commit this file and deploy again using eb deploy.