ruby rails on Nginx环境

安装ruby rails on Nginx环境

安装ruby环境

安装RVM

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
$ curl -sSL https://get.rvm.io | bash -s stable

# 若是上面的链接失败,能够尝试: nginx

$ curl -L https://raw.githubusercontent.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable

#添加环境变量git

source /usr/local/scripts/rvm

#修改 RVM 下载 Ruby 的源,到 Ruby China 的镜像:github

echo "ruby_url=https://cache.ruby-china.com/pub/ruby" > /usr/local/rvm/user/db

安装 ruby

rvm list known 
#查看ruby版本表
rvm install 2.5.6
#安装 2.5.6版本
rvm use 2.5.6 --default
#修改成系统默认版本
ruby -v
#查看ruby版本,证实安装成功

使用国内镜像源

$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l
# 确保只有 gems.ruby-china.com
https://gems.ruby-china.com

你能够用 Bundler 的 Gem 源代码镜像命令。web

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

## 安装 rails for nginx

### 首先使用gem安装passenger

gem install passengervim

  • 安装 nginx+passenger

    执行 passenger-install-nginx-module

    如系统末安装Nginx会自动安装,注意配置Nginx安装路径,若是系统已安装则哪须要添加配置项segmentfault

  • 采用编译方式安装Nginx并编译加入Ruby的Passenger模块

    1. 获取Passenger中nginx模块路径
passenger-config --root
  1. 在Nginx编译参数中带入passenger模块,执行编译安装
./configure \
--prefix=/usr/local/nginx \
--add-module=/usr/local/rvm/gems/ruby-2.3.8/gems/passenger-6.0.2/src/nginx_module \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-pcre
make && make install
  1. 添加Ningx开机启动脚本(Centos7)
vim /usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx - high performance web server 
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
systemctl enable nginx #添加到开机启动
systemctl start nginx  #启动nginx

配置nginx

#在http配置段
#passenger_root  #按上述输出实际修改
#passenger_ruby  #按上述输出实际修改
例

passenger_root /usr/local/rvm/gems/ruby-2.3.8/gems/passenger-6.0.2;
passenger_ruby /usr/local/rvm/gems/ruby-2.3.8/wrappers/ruby;ruby

#在server 段添加
    passenger_enabled on; 开启passenger

安装rails应用

将rails 源码部署nginx的web根目录bash

bundle install

# 参考文档
https://ruby-china.org/wiki/install_ruby_guide
https://segmentfault.com/a/1190000002911605
相关文章
相关标签/搜索