Skip to content

Instantly share code, notes, and snippets.

@bydmm
Last active August 29, 2015 14:12
Show Gist options
  • Save bydmm/0256aeb0dce9fa59c5a4 to your computer and use it in GitHub Desktop.
Save bydmm/0256aeb0dce9fa59c5a4 to your computer and use it in GitHub Desktop.
Install Rails with passenger4 on EC2 UBUNTU 14.04 TLS

首先设置语言

cd /usr/share/locales
sudo ./install-language-pack zh_CN

安装RUBY必要的环境依赖

sudo apt-get update
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libpq-dev imagemagick libmagickwand-dev

安装必要的服务

sudo apt-get memcached redis-server
# https://www.linode.com/docs/databases/redis/redis-on-ubuntu-12-04-precise-pangolin

将bashrc生效

cp ~/.profile ~/.bash_profile

add following code to ~/.bash_profile

# ~/.profile: executed by Bourne-compatible login shells.
if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n

使用RBENV安装RUBY

cd ~
git clone git://github.com/sstephenson/rbenv.git .rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL

git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL

rbenv install 2.1.3
rbenv global 2.1.3
ruby -v

安装 Phusion Passenger

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
sudo apt-get install apt-transport-https ca-certificates
sudo vim /etc/apt/sources.list.d/passenger.list

insert one of the following lines, depending on your distribution.

deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main
sudo chown root: /etc/apt/sources.list.d/passenger.list
sudo chmod 600 /etc/apt/sources.list.d/passenger.list
sudo apt-get update

sudo apt-get install nginx-extras passenger

Edit /etc/nginx/nginx.conf and uncomment and change to this

passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /home/ubuntu/.rbenv/shims/ruby;
# passenger_friendly_error_pages on; for show error

配置虚拟主机

cd /etc/nginx/sites-available
sudo vim virtual-host-name
server {
  server_name virtual-host;
  listen 80;
  root /home/ubuntu/www/virtual_host_path/current/public;
  passenger_enabled on;
  rails_env staging; # ruby env
  underscores_in_headers on; # fuck nginx http://stackoverflow.com/questions/22856136/why-underscores-are-forbidden-in-http-header-names
  gzip on;
  gzip_http_version 1.1;
  gzip_disable "msie6";
  gzip_vary on;
  gzip_proxied any;
  gzip_types text/plain text/css text/xml application/xml application/xml+rss;
  location ~* \.(ico|css|gif|jp?g|png)(\?[0-9]+)?$ {
    expires max;
  }
}

www.pathsource.com 字幕配置

sudo vim /etc/ngnix/ngnix.conf
...
http {
...
resolver 8.8.8.8; //dns server
...
}

sudo vim /etc/nginx/sites-available/www.pathsource.com
server {
...
  location ~ /subtitles/(?<videoid>.*).vtt {
    proxy_pass http://hls.pathsource.com/$videoid/subtitles/$videoid.vtt;
    proxy_set_header Host hls.pathsource.com;
  }
...
}
...
sudo ln -nfs /etc/nginx/sites-available/virtual-host-name  /etc/nginx/sites-enabled/virtual-host-name

# Bundler
```shell
gem install bundler

服务器安装定时任务管理器

gem install whenever

使用mina架设服务器和配置数据库

sudo vim /etc/environment
添加 RAILS_ENV=production

本地部署命令

mina deploy # 部署 staging 环境
mina deploy on=live # 部署 production 环境
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment