#!/bin/bash set -e -x export DEBIAN_FRONTEND=noninteractive apt-get update cd /home/ubuntu # download nginx curl -O http://www.nginx.org/download/nginx-0.7.65.tar.gz && curl -O http://pushmodule.slact.net/downloads/nginx_http_push_module-0.692.tar.gz && tar -xzvf nginx-0.7.65.tar.gz && tar -xvzf nginx_http_push_module-0.692.tar.gz && curl -L -O http://downloads.sourceforge.net/pcre/pcre-8.01.tar.gz && tar -xzf pcre-8.01.tar.gz && apt-get install libssl-dev -y # compile nginx cd nginx-0.7.65 ./configure --add-module=../nginx_http_push_module-0.692 --with-http_flv_module --user=apache --group=apache --with-http_gzip_static_module --with-pcre=../pcre-8.01 make && make install # configure nginx mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/orig.nginx.conf # ec2 can't handle line breaks properly in user-data scripts # note also the escaped dollars echo -e "user apache;\nworker_processes 8;\n\nerror_log logs/error.log;\n\nevents {\n worker_connections 100024;\n}\n\n\nhttp {\n include mime.types;\n default_type application/octet-stream;\n \n sendfile on;\n keepalive_timeout 65;\n \n push_max_reserved_memory 250M;\n \n server {\n listen 80;\n server_name localhost;\n \n # proxy all requests to apache, which should run on a different port.\n location / {\n rewrite ^(.*) http://mclaren.com\$1;\n }\n # serve the feed ourselves\n location /feed {\n push_channel_group pushmodule_chat;\n \n location /feed/publish {\n set \$push_channel_id mclaren; #static channel id\n push_publisher;\n push_message_timeout 5m;\n push_message_buffer_length 0;\n }\n location /feed/subscribe {\n set \$push_channel_id mclaren; #static channel id\n push_subscriber;\n send_timeout 3600; #so that nginx won't drop connections willy-nilly\n }\n }\n location = /test.html {\n root /var/www/html/test;\n }\n }\n}" >/usr/local/nginx/conf/nginx.conf # add nginx user groupadd apache useradd -c "Apache Server" -d /dev/null -g apache -s /bin/false apache # configure limits for performance ulimit -n 999999 echo "* hard nofile 999999" >>/etc/security/limits.conf echo "* hard nproc 999999" >>/etc/security/limits.conf echo "* soft nofile 999999" >>/etc/security/limits.conf echo "* soft nproc 999999" >>/etc/security/limits.conf echo "1024 65535" > /proc/sys/net/ipv4/ip_local_port_range # add more ephemeral ports # run nginx /usr/local/nginx/sbin/nginx echo "any subsequent errors are not the fault of nginx startup script"