在一个小内存的VPS上配置实在是痛苦啊。。。。没法用REE,没法用Passenger。。。编译过程中提示内存不够,真囧啊。。。。。Debian是5.0,内存是128M,安装了Mysql5.0
首先用apt-get update & apt-get upgrade升级一下系统的包
找了一圈没找到ruby1.9的安装源。。。自己下载编译
tar xzvf ruby-1.9.0.tar.gz cd ruby-1.9.0 ./configure –prefix=/usr/local/ruby sudo make sudo make install
安装完成之后,修改系统的PATH,以便我们不用每次都手动进到ruby的安装目录
在/etc/profile文件中修改:
PATH="/usr/local/ruby/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
这样Ruby就安装好了,剩下的就是来安装相应的gem:
gem install rails gem install mysql2 gem install thin?
然后来配置Thin
参考http://wiki.rubyonrails.org/deployment/nginx-thin
执行
sudo thin install
会添加一个/etc/thin的目录,还会告诉你如何把Thin加为自动启动
on RedHat-like systems: $ sudo /sbin/chkconfig --level 345 thin on on Debian-like systems (Ubuntu): $ sudo /usr/sbin/update-rc.d -f thin defaults on Gentoo: $ sudo rc-update add thin default
接下来就是为网站配置
sudo thin config -C /etc/thin/<config-name>.yml -c <rails-app-root-path> --servers <number-of-threads> -e <environment>
替换<config-name>为自己的应用名称,替换<rails-app-root-path>为应用的根目录,替换<number-of-threads>为启动的线程数,也就是启动多少个Thin服务,替换<environment>为运行环境。
下面是两个例子:
$ sudo thin config -C /etc/thin/myapp.yml -c /var/rails/myapp --servers 5 -e production sudo thin config -C /etc/thin/myapp.yml -c /var/rails/myapp --servers 5 --socket /tmp/thin.myapp.sock -e production
这样会在/etc/thin文件夹下生成一个配置文件,类似这样:
--- pid: tmp/pids/thin.pid timeout: 30 log: log/thin.log max_conns: 1024 require: [] environment: production max_persistent_conns: 512 servers: 5 daemonize: true socket: /tmp/thin.myapp.sock chdir: /var/rails/myapp
然后就可以启动Thin服务了,在我的VPS上是用
/etc/init.d/thin start
启动的,也可以使用
service thin start
启动。
?
?
接下来安装Nginx
?
sudo apt-get install nginx
然后配置Nginx,下面是一个配置样例,可以根据需要修改:
user nginx; worker_processes 5; error_log /var/log/nginx.error.log; pid /var/run/nginx.pid; events { worker_connections 1024; } http { 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 /var/log/nginx.access.log main; sendfile on; keepalive_timeout 65; upstream thin_cluster { server unix:/tmp/thin.0.sock; server unix:/tmp/thin.1.sock; server unix:/tmp/thin.2.sock; server unix:/tmp/thin.3.sock; server unix:/tmp/thin.4.sock; } server { listen 80; server_name www.myserver.com; root /var/rails/mysapp/public; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect false; if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename.html) { rewrite (.*) $1.html break; } if (!-f $request_filename) { proxy_pass http://thin_cluster; break; } } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
这里注意,启动Nginx之前,可以用nginx -t检测一下配置文件是否正确
?
在启动之前还需要添加nginx用户组,否则会提示
[emerg]: getpwnam(“nginx”) failed
用以下命令添加:
sudo adduser –system –no-create-home –disabled-login –disabled-password –group nginx
然后启动Nginx服务即可!!
?
至于重启,我都是kill掉main和worker进程。。。然后再启动,还真没有找到好的重启办法。。。其它的都不管用,郁闷。。。。