prem911
prem911

Reputation: 286

How to override nginx in AWS Beanstalk environment

There are many situations where we need to override nginx conf in AWS beanstalk environment.

AWS Support suggests using a nginx.conf which is a copy from the beanstalk app by looking at /etc/nginx/nginx.conf in the instance. This is to be used as the base and then new configs or blocks to be added. Then use .ebextensions/nginx/nginx.conf with this content in the project. However, the biggest problem with this is that if the base nginx.conf is changed by AWS then it might be very difficult to first know when it has changed and then repeating the steps of copying it and then adding the overrides. Something like this

The other options that most of the websearches give is use of container_commands and creation of files in appdeploy or configdeploy In container_commands folks have suggested to modify /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf Something like this

The problem with this approach is that it works only when app is deployed and not when any beanstalk configuration has changed ( like changing an env var ).

My question is which is the better recommended way of overriding the nginx config.

Upvotes: 0

Views: 1419

Answers (1)

Taterhead
Taterhead

Reputation: 5951

To help keep your elastic beanstalk deployment manageable, please keep in mind a few things:

First: AWS will not make changes to any config in your Elastic Beanstalk production environment directly. Similarly, you should not make any changes in your production elastic beanstalk environment directly either.

AWS recommends you change your configuration in your development environment and redeploy via the console or via the Elastic Beanstalk Command Line Interface (CLI) when you want to make that change go live. This is regardless of containerized or not, or load balanced or not, elastic beanstalk nginx config file or the override option.

Second: from the first link you provided: You either use the elastic beanstalk default nginx config OR the override config in .ebextensions. There is not a mix of both. This should help lessen your confusion. When you make changes to either in your development environment, this change implies a new version of your app, and you need to deploy it to your production to take effect.

Third: nginx can act as a proxy to your origin server and the origin server might be dictating a cache expire for assets. There are ways to change the configs on your nginx config to override the origin setting if needed. From the NGINX caching guide:

By default, NGINX respects the Cache-Control headers from origin servers. It does not cache responses with Cache-Control set to Private, No-Cache, or No-Store or with Set-Cookie in the response header. NGINX only caches GET and HEAD client requests.

I hope this helps clear things up. Deploy your app and keep these techniques in mind go ahead and deploy. If its wrong, delete it and try again.

Ask a more specific question regarding your application and specific config if you get stuck. The more details you provide to your question, the better we can help you.

Upvotes: 1

Related Questions