rails[6]:服务器部署

服务器环境:阿里云 ubuntu14.04
ubuntu的官方参考资料
更新服务器

apt-get update
apt-get upgrade

添加部署用户deploy,设置密码,并给予root权限

useradd deploy -m -s /bin/bash
passwd deploy
usermod -aG root deploy

sudo vi /etc/sudoers

deploy  ALL=(ALL:ALL) ALL

use deploy to login
ssh-copy-id [email protected]

sudo mkdir /var/www
sudo chown deploy:deploy /var/www

安装rvm和ruby,配置gem

sudo apt-get install -y curl git nodejs
\curl -sSL https://get.rvm.io | bash
source ~/.rvm/scripts/rvm
rvm requirements
rvm install 2.3.4

添加gem配置文件(使用其他编辑器也可以)vi ~/.gemrc

gem: "--no-document"

切换gem的源

gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/

安装passenger

gem install passenger
gem install bundler

替换默认的源

bundle config mirror.https://rubygems.org https://gems.ruby-china.org

安装nginx(如果内存较小,可能需要更多操作,请按照提示操作即可)

rvmsudo passenger-install-nginx-module
# symlink nginx conf folder to /etc/nginx
sudo ln -s /opt/nginx/conf /etc/nginx
# download linode nginx init script and create the service
wget -O init-deb.sh http://library.linode.com/assets/660-init-deb.sh
sudo mv init-deb.sh /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

安装mysql

sudo apt-get install mysql-server libmysqlclient-dev

安装imagemagick(图片处理)

sudo apt-get install imagemagick libmagickwand-dev

修改 nginx的conf文件

vi /opt/nginx/conf/nginx.conf
    server {
        listen       80;
        server_name example.com; # 这里填写你真实域名
        location / {
            root   /var/www/exmaple.com/current/public/;
            index  index.html index.htm;
            passenger_enabled on;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

你可能感兴趣的:(rails[6]:服务器部署)