I have an AWS Elasticbeanstalk Python environment and I'd like to change default 1 MB nginx configuration limit for file upload to a bigger value (15 MB).
So I thought to add a config file in .ebextensions:
files:
"/tmp/my.nginx.conf" :
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 15M;
"/tmp/install-nginx-config.sh" :
mode: "000755"
owner: root
group: root
content: |
#!/bin/sh
cp /tmp/my.nginx.conf /etc/nginx/conf.d/elasticbeanstalk/01_max-size.conf
container_commands:
01_runmyshellscript:
command: "sudo /tmp/install-nginx-config.sh"
02_reload_nginx:
command: "sudo service nginx reload"
The idea is to add the new config file in /etc/nginx/conf.d/elasticbeanstalk after the elasticbeanstalk nginx config files are created, so to no to to interfere with the creation of the EB environment, like suggested in many articles on Internet.
But if I deploy the above file in .ebextensions then the environment fails and if I SSH the EC2 I find out that in /etc/nginx/conf.d/elasticbeanstalk there is my 01_max-size.conf but the nginx configuration file created by Elasticbeanstalk isn't there anymore.
This is strange, beacause container_commands should be exetuced after the end of environment creation, so I have no clue of how solve this issue.
Related
So all I'm trying to do is add "client_max_body_size 5000m;" to my nginx.conf file.
I can ssh in and add the line manually, and that will work, but I know there's a way to do that automatically with my files in the .ebextensions folder.
If I use
files:
"/etc/nginx/nginx.conf":
mode: "000644"
owner: root
group: root
content: |
#Elastic Beanstalk Nginx Configuration File...
nothing seems to change.
if I use
files:
/.platform/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
#Elastic Beanstalk Nginx Configuration File...
I can see that the proxy.conf file is where I would expect it to be, but it still has no impact on my nginx settings, even though the AWS documentation and other posts on here would lead me to believe that EB should copy that file into /etc/nginx/conf.d/elasticbeanstalk/
but it does not, and manually specifying anywhere other than .platform doesn't seem to do anything.
I feel like I'm close, but for the life of me I can't figure it out.
You are trying to use (/etc/nginx/conf.d/proxy.conf) which is for Amazon Linux 1 (AL2). It will not work in AL2 as you should be using .platform/nginx/conf.d/, NOT .ebextentions as shown in the docs.
Therefore, you could have the following .platform/nginx/conf.d/myconfig.conf with content:
client_max_body_size 5000M;
I'm deploying with elasticbeanstalk with codePipeline.
I have to increase file size be uploaded,
so I add 02_nginx.config file is my app directory (.ebextensions).
Here is my -2_nginx_config
#Elastic Beanstalk configuration for 413 Request Entity Too Large:.
container_commands:
01_reload_nginx:`enter code here`
command: "sudo service nginx reload"
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000644"
owner: root
group: root
content: |
client_max_body_size 100M;
and there is a issue when deploy it.
Here is the message:
Deployment completed, but with errors: Failed to deploy application. The configuration file .ebextensions/02_nginx.config in application version code-pipeline-1600053611774-BuildArtifact-5e317627-6a37-4548-aa47-f6d4ebb03e2f contains invalid YAML or JSON. YAML exception: Invalid Yaml: while scanning a simple key in "<reader>", line 13, column 3: client_max_body_size 0; ^ could not found expected ':' in "<reader>", line 14, column 1: ^ , JSON exception: Invalid JSON: Unexpected character (#) at position 0.. Update the configuration file.
What is problem?
The nginx setting you are trying to use (/etc/nginx/conf.d/proxy.conf) is for Amazon Linux 1.
Since you are probably using Amazon Linux 2 you should be using different files for setting nginx. For AL2, the nginx settings should be in .platform/nginx/conf.d/, not in .ebextentions as shown in the docs.
Therefore, you could have the following .platform/nginx/conf.d/myconfig.conf with content:
client_max_body_size 100M;
Also you don't need to restart the nginx if you use .platform. So basically, replace your my-2_nginx_config with the .platform/nginx/conf.d/myconfig.conf
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;
I want to config the nginx config with the ebextension at Amazon Elastic Beanstalk,
The content of the conf as below:
files:
"/etc/nginx/conf.d/custom-nginx-proxy.conf" :
mode: "000755"
owner: "root"
group: "root"
content: |
client_max_body_size 60M;
contatiner_commands:
reload_nginx:
command: "sudo service nginx reload"
but always got the error about the content,
nginx: [emerg] unknown directive "files:" in /var/elasticbeanstalk/staging/nginx/conf.d/custom-nginx-proxy.conf:7
I put this file at
ROOT.war
|- ROOT/
|- .ebextensions
|- nginx
|- conf.d
|- custom-nginx-proxy.conf
|- Others content
Your extension should be placed at .ebextensions/01-custom-nginx-proxy.config. Also, the second block should start with container_commands:, not contatiner_commands:, and you don't need sudo as the deployment will already be running as root. If that doesn't help, try using two spaces per indent level. EB extensions are written in YAML, which is very sensitive to whitespace.
If you're still stuck, please post the contents of /var/elasticbeanstalk/staging/nginx/conf.d/custom-nginx-proxy.conf - the file that gets created after your deployment.
I have been struggling for the past few days now to increase the upload limit on nginx, which is apart my elastic beanstalk instance. From my understanding i need an ebextensions file to set the client_max_body_size. Which I have tried several different ways to configure, like directly overwriting nginx.conf to inserting client_max_body_size in nginx.conf on the live server. None of these methods have worked. I was sure to manually reload the file just after each attempt. As it stands, this is what my config file looks like at the moment(after several iteration):
.ebextensions/01_nginx.config
files:
/etc/nginx/conf.d/proxy.conf:
content: |
client_max_body_size 2G;
If anyone can help me that would be awesome.
You can either extend it or override it.
Elastic Beanstalk provides a default nginx configuration that you can
either extend or override completely with your own configuration
Overriding
~/workspace/my-app/
|-- .ebextensions
| `-- nginx
| `-- conf.d
| `-- myconf.conf
Source
Your Config looks right from your question compared to the example from the docs. Verify location of your nginx conf by sshing into the
$ eb ssh environment-name
$ sudo service nginx configtest
nginx: the configuration file /${LOCATION}/nginx.conf syntax is ok
nginx: configuration file /${LOCATION}/nginx.conf test is successful
Doc Example
"/home/ec2-user/myfile2" :
content: |
# this is my file
# with content
Also try adding the nginx reload to the .ebextensions if you have the right path to your nginx config.
files:
/etc/nginx/conf.d/proxy.conf:
mode: "000644"
owner: root
group: root
content: |
client_max_body_size 2G;
commands:
01_reload_nginx:
command: "sudo service nginx reload"
Source
Helpful blog post that runs thru most of this: "Getting to Know and Love AWS Elastic Beanstalk Configuration Files"(.ebextensions)
This might be helpful as it worked for me. Taking reference form aws ebs docs
To extend the Elastic Beanstalk default nginx configuration, add .conf configuration files to a folder named .platform/nginx/conf.d/ in your application source bundle. The Elastic Beanstalk nginx configuration includes .conf files in this folder automatically.
~/workspace/my-app/
|-- .platform
| `-- nginx
| `-- conf.d
| `-- myconf.conf
`-- other source files
myconf.conf
client_max_body_size 50M;
Note
When you add or edit an nginx .conf configuration file, be sure to encode it as UTF-8.