β

rails4发布production版备忘

陈钢的博客 141 阅读

1、编译css和js

执行

RAILS_ENV=production rake assets:precompile

如果出现错误

did not recognize your adapter specification

如果multi_json不是版本1.7.9这个有问题的版本,则在Gemfile中增加

gem 'yajl-ruby', :require => "yajl"

2、设置环境变量

export HANGUOMV_DATABASE_PASSWORD=xxxxx
export SECRET_KEY_BASE=xxxxx

3、初始化production的数据库

RAILS_ENV=productionrake db:create
RAILS_ENV=productionrake db:migrate

4、启动production的thin

rails s -p 3100 -b 127.0.0.1 -e production -P /var/www/rails/site/tmp/pids/server3100.pid -d
rails s -p 3101 -b 127.0.0.1 -e production -P /var/www/rails/site/tmp/pids/server3101.pid -d

5、配置httpd服务

<VirtualHost *:80>
    ServerName www.site.com
    DocumentRoot /var/www/rails/site/public
    ErrorLog logs/www.site.com-error_log
    CustomLog logs/www.site.com-access_log common
    ProxyRequests Off
    <Proxy balancer://site>
        BalancerMember http://127.0.0.1:3100
        BalancerMember http://127.0.0.1:3101
    </Proxy>
    ProxyPass /assets !
    ProxyPass /robots.txt !
    ProxyPass /favicon.ico !
    #ProxyPass / http://127.0.0.1:3100/ connectiontimeout=5 timeout=30
    ProxyPass / balancer://site/
    ProxyPassReverse / balancer://site/
</VirtualHost>

6、启动服务

systemctl restart httpd

7、设置自启动

在/etc/rc.local中添加

cd /var/www/rails/hanguomv && SECRET_KEY_BASE=xxx rails s -p 3100 -b 127.0.0.1 -e production -P /var/www/rails/site/tmp/pids/server3100.pid -d && cd /root
cd /var/www/rails/hanguomv && SECRET_KEY_BASE=xxx rails s -p 3101 -b 127.0.0.1 -e production -P /var/www/rails/site/tmp/pids/server3101.pid -d && cd /root

© chen for 陈钢的博客, 2014. | 原文链接 | 备忘
Post tags: httpd, rails, ruby, thin

作者:陈钢的博客
记录生活和技术的点滴
原文地址:rails4发布production版备忘, 感谢原作者分享。

发表评论