首页 > 代码库 > PassengerNginxdebian快速部署Rails

PassengerNginxdebian快速部署Rails

Passenger/Nginx/Debian快速部署Rails

 
PassengerNginxdebian快速部署Rails
 

 

 

安装所需的linux包

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev  libxml2-dev libxslt-dev autoconf libc6-dev zlib1g-dev libssl-dev build-essential curl git-core libc6-dev g++ gcc

添加一个rails用户

sudo adduser railsusudo usermod -G passenger,www-data,sudo railsusu - railsu

安装 rvm

bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

加载rvm (只需第一次安装时加载)

source .bashrc

安装ruby

rvm install 1.9.2

rvm 高阶应用可以参考这里的指南

安装 passenger/nginx

rvm use 1.9.2 defaultgem install passengerrvmsudo passenger-install-nginx-module

所有都选默认,选择下载并编译passenger.
nginx安装目录也选择默认 /opt/nginx/

passenger 会自动修改config, 添加passenger所在的rvm的ruby和gem环境地址。

安装nginx启动脚本(这里的脚本如果有问题使用 (@debian:~/文档/ruby/blogs$ sudo /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf)

安装所需的linux包

sudo apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev  libxml2-dev libxslt-dev autoconf libc6-dev zlib1g-dev libssl-dev build-essential curl git-core libc6-dev g++ gcc

添加一个rails用户

sudo adduser railsusudo usermod -G passenger,www-data,sudo railsusu - railsu

安装 rvm

bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)

加载rvm (只需第一次安装时加载)

source .bashrc

安装ruby

rvm install 1.9.2

rvm 高阶应用可以参考这里的指南

安装 passenger/nginx

rvm use 1.9.2 defaultgem install passengerrvmsudo passenger-install-nginx-module

所有都选默认,选择下载并编译passenger.
nginx安装目录也选择默认 /opt/nginx/

passenger 会自动修改config, 添加passenger所在的rvm的ruby和gem环境地址。

安装nginx启动脚本

wget https://raw.github.com/gist/1548664/53f6d7ccb9dfc82a50c95e9f6e2e60dc59e4c2fb/nginxsudo cp nginx /etc/init.d/sudo chmod +x /etc/init.d/nginxsudo update-rc.d nginx defaults

配置nginx

配置编辑nginx文件
sudo gedit /opt/nginx/conf/nginx.conf

配置文件在 /opt/nginx/config/nginx.conf

server {   listen 80;   server_name www.yourhost.com;   root /home/railsu/project/public;   # <--- 这里是你项目的public目录   passenger_enabled on;}

搞定你的数据库

  • 如果是MongoDB, 可以参考这里的部署方案

安装node.js

用来precompile rails assets

sudo apt-get install python-software-propertiessudo add-apt-repository ppa:chris-lea/node.jssudo apt-get updatesudo apt-get install nodejs

precompile assets

cd ~/projectrake assets:precompile

启动

sudo /etc/init.d/nginx start
 

))

wget https://raw.github.com/gist/1548664/53f6d7ccb9dfc82a50c95e9f6e2e60dc59e4c2fb/nginxsudo cp nginx /etc/init.d/sudo chmod +x /etc/init.d/nginxsudo update-rc.d nginx defaults

配置nginx

配置文件在 /opt/nginx/config/nginx.conf

server {   listen 80;   server_name www.yourhost.com;   root /home/railsu/project/public;   # <--- 这里是你项目的public目录   passenger_enabled on;}

搞定你的数据库

  • 如果是MongoDB, 可以参考这里的部署方案

安装node.js

用来precompile rails assets

sudo apt-get install python-software-propertiessudo add-apt-repository ppa:chris-lea/node.jssudo apt-get updatesudo apt-get install nodejs

precompile assets

cd ~/projectrake assets:precompile

启动

sudo /etc/init.d/nginx start
 
 

启动nginx
sudo /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf

查看nginx 进程
ps aux | grep nginx
杀死进程之后重启
sudo kill 111111

 

查看日志

@debian:~/文档/ruby/blogs$ tail -f log/production.log
@debian:~/文档/ruby/blogs$ tail -f log/development.log 
 

Nginx中文资料

http://wiki.nginx.org/NginxChs
http://www.nginx.cn/
http://www.nginx.cn/nginx-how-to
 
https://github.com/halida/blog/blob/master/unicorn%E9%85%8D%E7%BD%AE.rst

PassengerNginxdebian快速部署Rails