Forked from iwarshak/rightscale nginx+passenger script
Created
April 20, 2009 17:11
-
-
Save efalcao/98623 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
if test "$RS_REBOOT" = "true" ; then | |
echo "Skip HTTPD install on reboot." | |
logger -t RightScale "Skip nginx install on reboot." | |
service nginx start | |
exit 0 # Leave with a smile ... | |
fi | |
######################################## | |
# Install Passenger with an expect script | |
######################################## | |
gem install passenger | |
passenger-install-nginx-module --auto --auto-download --prefix=/opt/nginx | |
echo "Done installing passenger and nginx" | |
######################################## | |
# Configure nginx | |
######################################## | |
NGINX_CONFIG="/opt/nginx/conf/nginx.conf" | |
cat <<EOF > $NGINX_CONFIG | |
#user nobody; | |
worker_processes 1; | |
#error_log logs/error.log; | |
#error_log logs/error.log notice; | |
#error_log logs/error.log info; | |
#pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
passenger_root `passenger-config --root`; | |
passenger_ruby /usr/bin/ruby; | |
#log_format main '\$remote_addr - \$remote_user [\$time_local] \$request ' | |
# '"\$status" \\$body_bytes_sent "\\$http_referer" ' | |
# '"\$http_user_agent" "\$http_x_forwarded_for"'; | |
#access_log logs/access.log main; | |
sendfile on; | |
#tcp_nopush on; | |
#keepalive_timeout 0; | |
keepalive_timeout 65; | |
#gzip on; | |
server { | |
listen 80; | |
server_name www.$WEB_PUBLIC_HOSTNAME $WEB_PUBLIC_HOSTNAME; | |
EOF | |
if [ $ENABLE_WWW_REDIRECTION ]; then | |
cat <<EOF >> $NGINX_CONFIG | |
if (\$host !~* www\.(.*)) { | |
rewrite ^(.*)\$ http://www.\$host\$1 permanent; | |
} | |
EOF | |
fi | |
cat <<EOF >> $NGINX_CONFIG | |
root /home/rails/$APPLICATION/current/public; | |
passenger_enabled on; | |
} | |
EOF | |
if [ $SSL_CERT ]; then | |
cat <<EOF >> $NGINX_CONFIG | |
# HTTPS server | |
server { | |
listen 443; | |
server_name www.$WEB_PUBLIC_HOSTNAME $WEB_PUBLIC_HOSTNAME; | |
EOF | |
if [ $ENABLE_WWW_REDIRECTION ]; then | |
cat <<EOF >> $NGINX_CONFIG | |
if (\$host !~* www\.(.*)) { | |
rewrite ^(.*)\$ https://www.\$host\$1 permanent; | |
} | |
EOF | |
fi | |
cat <<EOF >> $NGINX_CONFIG | |
ssl on; | |
ssl_certificate $SSL_CERT; | |
ssl_certificate_key $SSL_CERT_KEY; | |
ssl_session_timeout 5m; | |
ssl_protocols SSLv2 SSLv3 TLSv1; | |
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; | |
ssl_prefer_server_ciphers on; | |
root /home/rails/$APPLICATION/current/public; | |
passenger_enabled on; | |
} | |
EOF | |
fi | |
cat <<EOF >> $NGINX_CONFIG | |
} | |
EOF | |
##################### | |
# Start nginx | |
##################### | |
/opt/nginx/sbin/nginx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment