如何把 rails 项目部署到 VPS
1. 装包
sudo apt-get updatesudo adduser deployer --ingroup sudosudo apt-get -y install git-coresudo apt-get -y install libmysqlclient-devsudo apt-get -y install libxml2-dev libxslt1-dev
2. rbenv & ruby & bundler
curl https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bashrbenv bootstrap-ubuntu-12-04rbenv install 1.9.3-p125rbenv global 1.9.3-p125gem install bundler --no-ri --no-rdocrbenv rehash
3. nginx
sudo apt-get install python-software-propertiessudo add-apt-repository ppa:nginx/stablesudo apt-get updatesudo apt-get -y install nginxsudo ln -s /home/peter/happycasts/config/nginx.conf /etc/nginx/sites-enabled/happycastssudo rm /etc/nginx/sites-enabled/defaultsudo service nginx start
upstream unicorn { server unix:/tmp/unicorn.happycasts.sock fail_timeout=0;}
server { listen 80 default deferred; # server_name example.com; root /home/peter/happycasts/public;
location ^~ /assets/ { gzip_static on; expires max; add_header Cache-Control public; }
try_files $uri/index.html $uri @unicorn; location @unicorn { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://unicorn; }
error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10;}
4. unicorn
kill -9 `cat tmp/pids/unicorn.pid`unicorn -D -c config/unicorn.rb -E productionps aux|grep unicornmkdir -p tmp/pidstouch tmp/pids/unicorn.pidmkdir log/touch log/unicorn.log
root = "/home/deployer/happycasts/"working_directory rootpid "#{root}/tmp/pids/unicorn.pid"stderr_path "#{root}/log/unicorn.log"stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.happycasts.sock"worker_processes 2timeout 30