Skip to content

Instantly share code, notes, and snippets.

@gthomas
Forked from nzakas/replace-apache.sh
Created September 26, 2013 17:52
Show Gist options
  • Save gthomas/6717948 to your computer and use it in GitHub Desktop.
Save gthomas/6717948 to your computer and use it in GitHub Desktop.
#!/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'
@stephenlb
Copy link

Line 58: good call :-)

@stephenlb
Copy link

Make sure to update OS fd limits (FD limits on User/Process/System levels). And no need to worry about TCP Tuning these days on modern OS.

ulimit -n ## Test Current FD limit.

@stephenlb
Copy link

what kind of process runs on port 127.0.0.1:8080

@gthomas
Copy link
Author

gthomas commented Nov 18, 2013

@stephenlb -- we decided not to use this and rolled our own servers, but it is pretty neat.

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