public
Last active

Replace Apache with nginx on Elastic Beanstalk AMI (Tomcat7/32-bit)

  • Download Gist
replace-apache.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
#!/bin/sh
# IMPORTANT: Run this script as sudo or else it won't work
# Original script: http://my.safaribooksonline.com/book/programming/java/9781449309558/hacking-elastic-beanstalk/hackingelectric#X2ludGVybmFsX0ZsYXNoUmVhZGVyP3htbGlkPTk3ODE0NDkzMDk1NTgvSV9zZWN0MTRfZDFlMjAyNQ==
 
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 / {
proxy_pass http://127.0.0.1:8080/;
}
 
# make sure the hostmanager works
location /_hostmanager/ {
proxy_pass http://127.0.0.1:8999/;
}
}' > /etc/nginx/conf.d/beanstalk.conf
 
echo 'Making sure that nginx starts on startup'
/sbin/chkconfig nginx on
 
echo 'Removing Apache...no longer needed'
yum remove httpd
 
echo 'Done'

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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.