Created
February 25, 2012 17:29
-
-
Save alanstevens/1909640 to your computer and use it in GitHub Desktop.
Script to setup the web server for Rails on an Ubuntu server
This file contains hidden or 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 | |
# | |
# Install nginx & passenger build dependencies | |
# | |
apt-get install libcurl4-openssl-dev --yes | |
apt-get install libpcre3 libpcre3-dev --yes | |
# | |
# source rvm in the current shell session | |
# | |
source /etc/profile.d/rvm.sh | |
# | |
# Install Ruby and set system defaults | |
# | |
rvm install 1.9.2 | |
rvm use 1.9.2 --default | |
rvm use 1.9.2@global | |
gem install rails --version 3.2.2 --no-rdoc --no-ri | |
gem install bundler --no-rdoc --no-ri | |
# | |
# Install unicorn gem in the default gemset | |
# | |
gem install unicorn --no-rdoc --no-ri | |
# | |
# Build and Install Nginx and Passenger | |
# | |
gem install passenger --no-rdoc --no-ri | |
curl http://nginx.org/download/nginx-1.0.12.tar.gz -o /tmp/nginx-1.0.12.tar.gz | |
tar -zxvf /tmp/nginx-1.0.12.tar.gz -C /tmp | |
rvmsudo passenger-install-nginx-module --auto --prefix=/usr/local/nginx --nginx-source-dir=/tmp/nginx-1.0.12 --extra-configure-flags="--conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid --with-http_ssl_module" | |
# --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --lock-path=/var/lock/nginx.lock --http-client-body-temp-path=/var/lib/nginx/body --http-proxy-temp-path=/var/lib/nginx/proxy --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --user=www-data --group=www-data" | |
# | |
# Use recommended config from: http://articles.slicehost.com/2007/12/13/ubuntu-gutsy-nginx-configuration-1 | |
# | |
mkdir /etc/nginx/sites-available | |
mkdir /etc/nginx/sites-enabled | |
rm -f /etc/nginx/nginx.conf | |
#curl https://raw.github.com/defunkt/unicorn/master/examples/nginx.conf | sed 's|root path/to/app/current/public;|root /var/www/;|g' > ~/nginx.conf | |
cat <<-File > /etc/nginx/nginx.conf | |
user www-data www-data; | |
worker_processes 4; | |
error_log /var/log/nginx/error.log; | |
pid /var/run/nginx.pid; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
access_log /var/log/nginx/access.log; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay off; | |
keepalive_timeout 4; | |
gzip on; | |
gzip_comp_level 2; | |
gzip_proxied any; | |
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript; | |
include /etc/nginx/sites-enabled/*; | |
} | |
File | |
# | |
# Create an example passenger site config | |
# | |
cat <<-File > /etc/nginx/sites-available/default | |
server { | |
listen 80; | |
server_name localhost; | |
root /var/www/myapplication/public; # <--- be sure to point to 'public'! | |
passenger_enabled on; | |
} | |
File | |
ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default | |
chown www-data:www-data /etc/nginx/nginx.conf | |
chmod 0644 /etc/nginx/nginx.conf | |
rm -f /etc/init.d/nginx | |
curl -s https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx > /etc/init.d/nginx | |
chmod +x /etc/init.d/nginx | |
# | |
# Create a init script for Unicorn | |
# | |
curl -s https://raw.github.com/railscasts/episode-293/master/todo-after/config/unicorn_init.sh > /etc/init.d/unicorn | |
chmod +x /etc/init.d/unicorn | |
# | |
# give permissions on /var/www to the web group: | |
# | |
mkdir /var/www | |
chgrp -R www-data /var/www | |
chmod -R 775 /var/www # group write permission | |
# | |
# Start nginx | |
# | |
/etc/init.d/nginx start | |
/usr/sbin/update-rc.d -f nginx defaults | |
# | |
# start Unicorn | |
# | |
/etc/init.d/unicorn start | |
/usr/sbin/update-rc.d -f unicorn defaults |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment