Ubuntu下安装 ROR 环境以及 passenger+nginx 配置

为了方便下次配置-----记下来.


#更新资源

1. $ sudo apt-get update

#安装需要的环境

2. $ sudo apt-get install -y wget vim build-essential openssl libreadline6 libreadline6-dev libmysqlclient-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libxml2-dev libxslt-dev libcurl4-openssl-dev autoconf automake libtool imagemagick libmagickwand-dev libpcre3-dev nodejs libpq-dev

#安装rvm

3. $ sudo su -
   $ \curl -L https://get.rvm.io | bash -s stable

#写入环境变量

4. $ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm"' >>~/.bashrc
   $ source ~/.bashrc
   $ rvm -v #查看rvm版本(如果无法查看可以重启终端 然后再次输入这个命令)



#如果你是国内服务器,推荐将 RVM 的安装源替换成 Taobao 的镜像服务器,这样安装能更快!

5. $ sed -i -e 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' /usr/local/rvm/config/db

#用 RVM 安装 Ruby

6. $ rvm pkg install readline openssl  (每次都会有错,不用理会错误接着往下)


#安装ruby

7. $ rvm install 2.0.0 (一般会安装2.0.0的最新版)


#指定默认ruby版本

8. $ rvm use 2.0.0 --default


#查看ruby版本

9. $ ruby -v


#替换镜像

10. $ gem sources --remove https://rubygems.org/
    $ gem sources -a http://ruby.taobao.org/
    $ gem sources -l

看到结果 :

*** CURRENT SOURCES ***

http://ruby.taobao.org


#安装rails

11. $ gem install rails (默认是安装最新 4.0 可以指定版本 gem install rails -v 3.2.13)


#安装passenger

12. $ gem install passenger
      $ passenger -v (查看版本)


#安装nginx

由于 Passenger 需要重新编译 Nginx,如果你之前有安装 Nginx 需要卸载掉!

nginx -v,有的话卸载 $ sudo apt-get remove nginx-common nginx-full nginx

13. $ sudo passenger-install-nginx-module

最后会看到 : Nginx with Passenger support was successfully installed.


#删除nginx本身的页面

14. $ sudo rm -rf /opt/nginx/html/index.html


#配置 Nginx 与网站


15. $ sudo vim /opt/nginx/conf/nginx.conf

#我配置的demo


user shengshihui; # 修改成你的系统帐号名,不然项目目录 /home/shengshihui/www 这里没有权限
#user  nobody;
worker_processes  4;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    passenger_root /usr/local/rvm/gems/ruby-2.0.0-p195/gems/passenger-4.0.20;
    passenger_ruby /usr/local/rvm/wrappers/ruby-2.0.0-p195/ruby;
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    client_max_body_size 500m;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 16k;
    #gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
    gzip_vary off;
    gzip_disable "MSIE [1-6]\.";
    server {
        listen       80;
        server_name  localhost;
        root /home/shengshihui/www/ror/dotshouji_server/public;
        passenger_enabled on;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}


#接下来你需要安装 Nginx 的启动脚本,以及配置开机自动启动


$ cd ~/
$ git clone git://github.com/jnstq/rails-nginx-passenger-ubuntu.git
$ sudo mv rails-nginx-passenger-ubuntu/nginx/nginx /etc/init.d/nginx
$ sudo chmod +x /etc/init.d/nginx


#配置 Nginx 开机自启动

$ sudo update-rc.d nginx defaults



你可能感兴趣的:(nginx,ubuntu,passenger,ror)