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
-- nginx      -- conf.d
-- proxy.conf <p>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.</p> <p>This all works because the default nginx.conf file- on line 21 -specifies to include all .conf files under the conf.d directory:</p> <p>The directives from the .conf file will be added to the <em>http</em> block of the default configuration.</p> <p>If you need to add directives to the <em>server</em> block you will need to add .conf files to the elasticbeanstalk folder (see line 39 of previous Gist). That dir structure would look:</p> .ebextensions-- nginx
-- conf.d      |    -- elasticbeanstalk |
-- my_other_conf.conf      -- proxy.conf
Same can be done for an Apache proxy. The difference is on the directory structure. For Apache your structure should be this:.ebextensions
-- httpd      -- conf `-- proxy.conf
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.