Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Replace Apache with nginx on Elastic Beanstalk AMI (Tomcat7/32-bit)
# IMPORTANT: Run this script as sudo or else it won't work
# Original script:
echo 'Installing nginx...sit tight'
yum -y install nginx
echo 'Fixing nginx configuration'
sed -i 's/ 1;/ 4;/g' /etc/nginx/nginx.conf
rm /etc/nginx/conf.d/default.conf
echo 'Messing around with hostmanager so nginx works with it'
cd /opt/elasticbeanstalk/srv/hostmanager/lib/elasticbeanstalk/hostmanager
cp utils/apacheutil.rb utils/nginxutil.rb
sed -i 's/Apache/Nginx/g' utils/nginxutil.rb
sed -i 's/apache/nginx/g' utils/nginxutil.rb
sed -i 's/httpd/nginx/g' utils/nginxutil.rb
cp init-tomcat.rb init-tomcat.rb.orig
sed -i 's/Apache/Nginx/g' init-tomcat.rb
sed -i 's/apache/nginx/g' init-tomcat.rb
echo 'Creating configuration files'
echo 'proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 10m;
client_body_buffer_size 128k;
client_header_buffer_size 64k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 16k;
proxy_buffers 32 16k;
proxy_busy_buffers_size 64k;' > /etc/nginx/conf.d/proxy.conf
echo 'server {
listen 80;
server_name _;
access_log /var/log/httpd/elasticbeanstalk-access_log;
error_log /var/log/httpd/elasticbeanstalk-error_log;
#set the default location
location / {
# make sure the hostmanager works
location /_hostmanager/ {
}' > /etc/nginx/conf.d/beanstalk.conf
echo 'Making sure that nginx starts on startup'
/sbin/chkconfig nginx on
echo 'Removing longer needed'
yum remove httpd
echo 'Done'
Copy link

gpeev commented Dec 17, 2013

Where are you finding this path /opt/elasticbeanstalk/srv
Its not in any beanstalk i have seen.

Copy link

alzap commented Jun 25, 2014

same here, I can't find /opt/elasticbeanstalk/srv path anywhere.

Copy link

timmaybrown commented Aug 9, 2014

would it be possible to make many sites this way on a single instance? eg: and I need the frontendapp to pull resources from the admin app. Each are separately managed repos. I haven't found how I could deploy two apps code bases to one single instance. Any thoughts would be appreciated.

Copy link

danielsilva commented Aug 26, 2014

Could not find /opt/elasticbeanstalk/srv path too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment