zoukankan      html  css  js  c++  java
  • 使用passenger在Centos7部署Puma+Nginx+Ruby on Rails

    安装ruby环境

    RVM(ruby版本管理工具)安装

    gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
    curl -sSL https://get.rvm.io | bash -s stable
    source /etc/profile.d/rvm.sh
    

    列出所有可用的ruby版本

    rvm list known
    

    安装一个ruby版本

    rvm install 2.2
    

    或者,安装最新版本

    rvm install ruby

    设置新版本ruby为默认版本

    rvm use 2.2 --default
    

    检查当前ruby版本

    ruby -v
    

    安装Nginx

    创建nginx源文件

    # vi /etc/yum.repos.d/nginx.repo

    [nginx]
    name=nginx repo
    baseurl=http://nginx.org/packages/centos/7/$basearch/
    gpgcheck=0
    enabled=1
    

    安装nginx

    yum -y install nginx
    

    启动nginx并设为自启动服务

    chkconfig nginx on
    service nginx start

    安装Rails和Puma

    由于国内网络原因,导致 rubygems.org 存放在 Amazon S3 上面的资源文件间歇性连接失败。

    解决办法:

    修改Ruby的gem源地址为淘宝的源

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

    检查Ruby的gem源

    gem sources -l
    

    安装rails

    gem install rails
    

    查看rails版本

    rails -v

    安装puma

    gem install puma
    

    查看puma版本

    puma --version

    启动puma

    首先,确保你把Puma加入了你的ruby应用的Gemfile文件中。

    gem 'puma'
    

    后用Rails命令启动Puma

    rails s Puma

    配置Nginx

    删除默认站点配置文件

    rm /etc/nginx/conf.d/default.conf

    为你的ruby应用创建一个站点配置文件

    # vi /etc/nginx/conf.d/my_app.conf

    upstream my_app {
      server unix:///var/run/my_app.sock;
    }
    
    server {
      listen 80;
      server_name my_app_url.com; # change to match your URL
      root /var/www/my_app/public; # I assume your app is located at this location
    
      location / {
        proxy_pass http://my_app; # match the name of upstream directive which is defined above
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
    
      location ~* ^/assets/ {
        # Per RFC2616 - 1 year maximum expiry
        expires 1y;
        add_header Cache-Control public;
    
        # Some browsers still send conditional-GET requests if there's a
        # Last-Modified header or an ETag header even if they haven't
        # reached the expiry date sent in the Expires header.
        add_header Last-Modified "";
        add_header ETag "";
        break;
      }
    }
    

    重启nginx

    service nginx restart
    
  • 相关阅读:
    2018.1.10 区块链论文翻译
    2018.1.9 区块链论文翻译
    2019.1.7 区块链论文翻译
    #在蓝懿iOS学习的日子#
    #在蓝懿学习iOSd的日子#
    #在蓝懿iOS学习的日子#2014年10月15日
    #蓝懿iOSi学习的日子#2015年10月14日
    #蓝懿ios学习的日子#2015年 10月13日
    #蓝懿ios学习的日子#2015年10月12鈤
    三种读写XML的方法
  • 原文地址:https://www.cnblogs.com/edward2013/p/5309078.html
Copyright © 2011-2022 走看看