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 &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;-- conf.d            -- proxy.conf <p>Now, when you deploy a new version of your application, ElasticBeanstalk will automatically copy your files on the .ebextensions &gt; nginx &gt; 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
&#xA0;
-- nginx       -- conf.d &#xA0;&#xA0;&#xA0;&#xA0; |&#xA0;&#xA0;&#xA0;&#xA0;-- elasticbeanstalk      |          -- my_other_conf.conf &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;-- 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 &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;-- conf            `-- proxy.conf

Wrap-up

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.