在阿里云 (aliyun) 服务器上搭建Ruby On Rails环境

来源:爱站网时间:2021-09-17编辑:网友分享
爱站技术小编最近总是在配置阿里云的服务器,遇到不少问题,现小结一下,里面的问题相信大家也遇到过,有需要的朋友可以来看看,文章仅供大家参考~~

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

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

$ mv sh.zip /home/tmp/ & cd /home/tmp
$ unzip sh.zip
$ chmod -R 777 sh & cd sh
# 任意选择一种方法执行脚本
# 方法一
$ ./install.sh
# 方法二
$ ./install_nginx_xxx.sh
$ ./install_mysql_xxx.sh

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

安装RVM与指定的Ruby版本

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

查看是否安装成功

$ ruby -v
ruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]
$ gem -v
2.1.9

更换 gem source,提高gem下载速度

$ gem source -r https://rubygems.org/ $ gem source -a http://ruby.taobao.org

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

安装git工具

$ yum install git

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

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

克隆你的项目

$ git clone path/to/your/project.git
# 安装项目指定gem包
$ cd path/to/your/project
$ bundle install

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

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

启动unicron生产环境

$ unicorn_rails -c config/unicorn.rb -E production -D

关闭unicorn进程

$ kill -9 $(cat tmp/pids/unicorn.pid )

5、配置nginx虚拟主机

添加nginx虚拟主机配置

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

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

upstream unicorn_server
{
 server unix:项目根目录/tmp/sockets/unicorn.sock fail_timeout=0;
}

server 
{
 listen    80;
 server_name 域名;
 root 项目根目录/public;
 location / 
 {
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-Host $host;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_buffering on;
  if (!-f $request_filename) {
    proxy_pass http://unicorn_server;
    break;
  }
 }

 location ~ ^/(assets)/ 
 {
   expires max;
   add_header Cache-Control public;
 }
}


友情提示

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

$ vim /etc/crontab

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

00 1 * * * echo 3 > /proc/sys/vm/drop_caches 

以上内容就是爱站技术频道小编为大家分享的在阿里云 (aliyun) 服务器上搭建Ruby On Rails环境,看完以上分享之后,大家应该都知道怎么搭建Ruby On Rails环境了吧。

上一篇:Ruby中使用Block、Proc、lambda实现闭包

下一篇:ruby线程实现生产者消费者问题示例(队列Queue实现线程同步)

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载