在阿里雲 (aliyun) 伺服器上搭建Ruby On Rails環境_ruby專題

來源:互聯網
上載者:User

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 -vruby 1.9.3p448 (2013-06-27 revision 41675) [i686-linux]$ gem -v2.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 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.