AWS ElasticBeanstalk applications use either an nginx or Apache proxy to relay requests. Using the .ebextensions feature of ElasticBeanstalk we can extend the configuration of these proxies. If you don't know how .ebextensions work you can read more here.
I'm going to extend the default nginx proxy configurations using .ebextensions. The same procedure can be used to extend an Apache proxy.
Create .conf file
First we need to create a .conf file with the desired directives. Here is mine- named proxy.conf -to increase some timeouts of the proxy:
Create nginx conf.d directory
Now we need the directory where our configuration file will be. Under .ebextensions, create a directory named 'nginx', and inside it another named 'conf.d'. Then add the file you just created. Your dir structure should look like this:.ebextensions
Now, when you deploy a new version of your application, ElasticBeanstalk will automatically copy your files on the .ebextensions > nginx > conf.d directory to the /etc/nginx/conf.d/ directory of your instances.
This all works because the default nginx.conf file- on line 21 -specifies to include all .conf files under the conf.d directory:
The directives from the .conf file will be added to the http block of the default configuration.
If you need to add directives to the server block you will need to add .conf files to the elasticbeanstalk folder (see line 39 of previous Gist). That dir structure would look:.ebextensions
| `-- elasticbeanstalk
| `-- my_other_conf.conf
Same can be done for an Apache proxy. The difference is on the directory structure. For Apache your structure should be this:.ebextensions
Using .ebextensions is by far the simplest method to add custom configurations to your nginx or Apache proxy. Create as many configuration files as you need and add them to the corresponding directory under .ebextensions and you are done.