安装环境:linux
数据库:sqlite3
我ruby和rails的版本
- ruby 2.0.0p247 (2013-06-27 revision 41674) [x86_64-linux]
- Rails 4.1.1
1.让你的项目在production上能够跑起来
- rails s -e production
可以先试一下,如果跑起来正常就不用配置,如果不正常,接这进行下面的配置
在gemfile文件中添加
- gem 'yaml_db'
接着执行
- bundle
记着每次更改gemfile文件都要执行bundle命令
修改config/database。yml文件为
- production:
- adapter: sqlite3
- encoding: utf8
- reconnect: false
- database: users //你的数据库表
- pool: 5
- username: root
- password: password
然后输入代码查看
- rake secret
会生成一段加密代码如:
- e666fd082bfa95dff96edb5fe3ea7b0800172b978dc1182bc99842439d16f50b4c2f409531da93d4f09efc5c6464429484c854ff052b8c6ab2ccc4e6868af73f
在config/secrets。yml中添加
- production:
- secret_key_base: e666fd082bfa95dff96edb5fe3ea7b0800172b978dc1182bc99842439d16f50b4c2f409531da93d4f09efc5c6464429484c854ff052b8c6ab2ccc4e6868af73f
最后执行命令让工程在production下跑起来
- rails s -e production
2.安装passager+nginx
安装passenger
- sudo gem install passenger
用passenger安装nginx
- sudo passenger-install-nginx-module
安装完成后nginx还启动不起来,需要安装nginx启动脚本
- cd ~/
- git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git
- sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx
- sudo chmod +x /etc/init.d/nginx
- <span style="font-family: Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', Consolas, 'Courier New', monospace; font-size: 12px; line-height: 18px; white-space: normal;">sudo update-rc.d nginx defaults</span>
3.配置nginx
以root身份打开nginx的默认安装目录/opt/nginx/conf/nginx.conf
- server {
- listen 80;
- server_name localhost; //需要配置到外网的话更改成你网站的域名
- #charset koi8-r;
- #access_log logs/host.access.log main;
- location / {
- root /home/tlt/Projects/rails/action/public; //你工程目录下的public
- passenger_enabled on;
- # index index.html index.htm index.haml;
- }
启动nginx
- sudo service nginx start
停止
- sudo service nginx stop
重启
- sudo service nginx restart