I want to use something like this nginx extension on an elastic beanstalk app - but how do I add/configure nginx on elastic beanstalk
2 Answers
I did a project awhile back that did dynamic image resizing on Elastic Beanstalk. I chose to do it in a Node.js app to get the speed and flexibility of libvips with the Sharp NPM package. It worked out in the end but doing this on Beanstalk was definitely an uphill battle.
The first problem we hit was with installing the libraries on the system. We needed imagemagick and libvips. A script setup in .ebextensions
works okay, but you don't get much control over when those scripts run in relation to your application. In our case, we needed the libraries installed before npm install
was run. That's not how Beanstalk works, so we had to do some really hacky stuff with devDependencies
in package.json
and then install them ourselves at the end of .ebextensions
scripts. For you, I'd imagine this is the first part of how you will install anything on the built-in Nginx instance. But, you will have to stop Nginx first as it is probably already running.
Next, Beanstalk likes to blow away any Nginx config you have. More specifically, it tries to merge your Nginx config with what Amazon wants. I suspect this is the part that will really bite you. We ended up giving up on this while trying to add some caching extensions. It never worked, and even if we hacked something in place it's likely it would have failed as soon as Amazon changed something later. You can put an Nginx config in place with .ebextensions
scripts, but as soon as they're done, Amazon has some script that rewrites the config anyway.
What I'm getting at is that you may be able to hack it to work, but this isn't something you want to do. Elastic Beanstalk is okay for what it's built for and basically nothing else. It also doesn't work quite as advertised, and is anything but a flexible system. It seems to be pieced together with a bunch of scripts on the box that do their job when used as intended, but messing with them isn't a good idea as Amazon can change how they function at any time.
One possibility for you is to use Docker. If I were to do the project again, I would have started with Docker right from the beginning, as in theory you can use whatever you want. Beanstalk can host your Docker applications, and it works differently than a normal Beanstalk application.
Best of luck with this project!

- 159,648
- 54
- 349
- 530
Well it turns out that nginx on Elastic Beanstalk is compiled with http_image_filter. So its basically a case of getting the nginx config into beanstalk's own nginx config. Yep @brad - that is a bit of a fudge. But its not too bad..
You can see my solution here. Basically its a python script which I've modified from this solution.