Nginx+mongrel+rails+ubuntu部署应用
我知道现在后端服务器有很多,但是为了与windows发布相对应,这里的后端选择mongrel。。。
思路:1.mongrel以守护进程方式运行rails
2.安装配置Nginx
一、mongrel以守护进程方式运行rails
1. 安装mongrel
gem 'mongrel'
2. 利用Nohup在后台运行命令
编写rails_env.bat,存放在/opt/下,内容为
cd /workspace/SVNMS/SVNMS /usr/local/bin/rails s mongrel -p 3003 -b 127.0.0.1
然后利用nohup在后台运行
nohup /opt/rails_svnms.bat &
可以用jobs命令查看后台运行进程
使用 fn %n 命令关闭后台运行进程
注意:运行nohup命令后,当shell中提示了nohup成功后还需要按终端上键盘任意键退回到shell输入命令窗口,然后通过在shell中输入exit来退出终端;
二、安装配置Nginx
1. 安装nginx
sudo apt-get install nginx
Ubuntu安装之后的文件结构大致为:
- 所有的配置文件都在/etc/nginx下,并且每个虚拟主机已经安排在了/etc/nginx/sites-available下
- 程序文件在/usr/sbin/nginx
- 日志放在了/var/log/nginx中
- 并已经在/etc/init.d/下创建了启动脚本nginx
- 默认的虚拟主机的目录设置在了/var/www/nginx-default (有的版本 默认的虚拟主机的目录设置在了/var/www, 请参考/etc/nginx/sites-available里的配置)
2.启动nginx
sudo /etc/init.d/nginx start
3.配置nginx
server {
listen 8083;
server_name liuwm-pc@grandsoft.com.cn;
root /workspace/SVNMS/SVNMS/public;
location / {
root /workspace/SVNMS/SVNMS/public;
proxy_set_header Host $host:8083;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://127.0.0.1:3003/;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}
#SSL
ssl on;
ssl_certificate /var/www/ssl/server.crt;
ssl_certificate_key /var/www/ssl/server.key;
ssl_client_certificate /var/www/ssl/ssl/ca.crt;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
三、将mongrel启动rails、nginx启动做成开机启动
Ubuntu开机之后会执行/etc/rc.local文件中的脚本,所以我们可以直接在/etc/rc.local中添加启动脚本。
当然要添加到语句:exit 0 前面才行。
在 exit 0 前面添加好脚本代码。
nohup /opt/rails_svnms.bat & sudo /etc/init.d/nginx start
参考:用Nohup命令让Linux下的程序在后台执行 http://www.linuxidc.com/Linux/2009-05/19963p2.htm
Ubuntu Nginx中文 http://wiki.ubuntu.org.cn/Nginx
Ubuntu添加开机自动启动程序的方法 http://www.linuxidc.com/Linux/2010-08/27668.htm
浙公网安备 33010602011771号