Extend nginx/Apache Proxy Configurations on AWS ElasticBeanstalk

David Ojeda - Jan 26 '18 - - Dev Community

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 a .conf file

First we need to create a .conf file with the desired directives. A list of nginx directives can be found here. My conf file- named proxy.conf -increases 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

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
    • nginx
      • conf.d
        • proxy.conf
      • 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
    • httpd
      • 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.

. . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player