安装ruby rails on Nginx环境安装ruby环境安装RVM

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

# 如果上面的连接失败,可以尝试:

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

#添加环境变量

source /usr/local/scripts/rvm

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

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.comhttps://gems.ruby-china.com

你可以用 Bundler 的 Gem 源代码镜像命令。

bundle config mirror.https://rubygems.org https://gems.ruby-china.com## 安装 rails for nginx### 首先使用gem安装passenger

gem install passenger

安装 nginx+passenger

执行 passenger-install-nginx-module

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

采用编译方式安装Nginx并编译加入Ruby的Passenger模块获取Passenger中nginx模块路径

passenger-config --root在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添加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=forkingPIDFile=/var/run/nginx.pidExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.confExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/bin/kill -s QUIT $MAINPIDPrivateTmp=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;

#在server 段添加 passenger_enabled on; 开启passenger安装rails应用

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

bundle install# 参考文档https://ruby-china.org/wiki/install_ruby_guidehttps://segmentfault.com/a/1190000002911605