zl程序教程

您现在的位置是:首页 >  硬件

当前栏目

在阿里云(aliyun)服务器上搭建RubyOnRails环境

服务器阿里 环境 搭建 aliyun RubyonRails
2023-06-13 09:15:28 时间

1、阿里云的一键安装web全环境

下载一键安装web全环境sh.zip压缩包
上传至服务器,解压、执行脚本,具体步骤详见这里

$mvsh.zip/home/tmp/&cd/home/tmp
$unzipsh.zip
$chmod-R777sh&cdsh
#任意选择一种方法执行脚本
#方法一
$./install.sh
#方法二
$./install_nginx_xxx.sh
$./install_mysql_xxx.sh

2、安装RVM与指定的Ruby版本

安装RVM与指定的Ruby版本

$curl-Lhttps://get.rvm.io|bash-sstable--ruby=1.9.3
#注意安装完成后,根据提示执行source命令

查看是否安装成功

$ruby-v
ruby1.9.3p448(2013-06-27revision41675)[i686-linux]
$gem-v
2.1.9

更换gemsource,提高gem下载速度

$gemsource-rhttps://rubygems.org/$gemsource-ahttp://ruby.taobao.org

3、安装git、编译javascript运行时环境node.js

安装git工具

$yuminstallgit

编译node.js(javascript运行时环境)

$gitclonehttps://github.com/joyent/node.git
$cdnode
$./configure&&make&&makeinstall
#如果无法编译,说名需要叫python升级到2.6或2.7
#如果缺少bz2,需要yuminstallbzip2-devel后,重新编译python

克隆你的项目

$gitclonepath/to/your/project.git
#安装项目指定gem包
$cdpath/to/your/project
$bundleinstall

4、配置unicorn文件并运行生产环境

查看unicorn配置实例config/unicorn.rb

启动unicron生产环境

$unicorn_rails-cconfig/unicorn.rb-Eproduction-D

关闭unicorn进程

$kill-9$(cattmp/pids/unicorn.pid)

5、配置nginx虚拟主机

添加nginx虚拟主机配置

$vim/path/to/your/nginx/vhosts/xxxx.conf

配置内容(将汉字替换成相应有效内容):

upstreamunicorn_server
{
serverunix:项目根目录/tmp/sockets/unicorn.sockfail_timeout=0;
}

server
{
listen80;
server_name域名;
root项目根目录/public;
location/
{
proxy_redirectoff;
proxy_set_headerHost$host;
proxy_set_headerX-Forwarded-Host$host;
proxy_set_headerX-Forwarded-Server$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
proxy_bufferingon;
if(!-f$request_filename){
proxy_passhttp://unicorn_server;
break;
}
}

location~^/(assets)/
{
expiresmax;
add_headerCache-Controlpublic;
}
}

友情提示

低内存服务器添加内存释放任务

$vim/etc/crontab

在最后一行添加如下内容(每天凌晨1点释放内存):

001***echo3>/proc/sys/vm/drop_caches