在windows平台下使用nginx和thin作为rails的服务器

由于mongrel已经年久失修、不支持最新的1.9.2版本了、所以现在使用thin作为rails服务器、再加上nginx作反向代理、

首先安装thin吧、在windows平台下、需要先安装eventmachine、否则不能安装thin服务器

gem install eventmachine --pre
gem install thin

安装完成后只需要在rails的项目目录上输入thin start就可以启动thin服务器了、

 

P.S.:有时候启动thin的时候会遇到这种错误、You have already activated rack 1.3.0, but your Gemfile requires rack 1.2.3.

这是因为迩安装了多个rack版本、环境造成混乱、请卸载掉不需要的版本或者修改了Gemfile再执行一次bundle install

 

接着莪们配置一下nginx吧、首先去nginx的官网找来nginx的windows版本、传送门:http://wiki.nginx.org/Install、下载完成后解压就可以使用了、进入nginx的conf目录、打开nginx.conf文件进行以下配置、

 1 worker_processes  1;
2 error_log C:/StandAlone/nginx/logs/error.log;
3 events {
4 worker_connections 1024;
5 }
6 http {
7 include mime.types;
8 default_type application/octet-stream;
9 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
10 '$status $body_bytes_sent "$http_referer" '
11 '"$http_user_agent" "$http_x_forwarded_for"';
12
13 sendfile on;
14 #keepalive_timeout 0;
15 keepalive_timeout 65;
16 #gzip on;
17 include C:/StandAlone/nginx/sites_enabled/*.txt;
18 }

注意error_log、include一定要切换成迩自己的实际目录、其中include狠重要、这个意思是从这个目录时加载其它外部配置、按着配置文件、莪们在nginx目录下新建sites_enabled文件夹吧、接下来在里面建立mystandaloneapp.com.txt文件、输入以下内容

 1 upstream mystandaloneapp {
2 server 127.0.0.1:3000;
3 }
4
5 server {
6 listen 80;
7 server_name localhost;
8 #charset koi8-r;
9
10 access_log C:/StandAlone/www/mystandaloneapp.com/log/access.log;
11 error_log C:/StandAlone/www/mystandaloneapp.com/log/error.log;
12 root C:/StandAlone/www/mystandaloneapp.com;
13 index index.html;
14
15 location / {
16 proxy_set_header X-Real-IP $remote_addr;
17 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
18 proxy_set_header Host $http_host;
19 proxy_redirect off;
20 try_files C:/StandAlone/www/maintenance.html $uri $uri/index.html $uri.html @ruby;
21 }
22
23 location @ruby {
24 proxy_pass http://mystandaloneapp;
25 }
26 }

这里的配置就是把thin的3000端口转化成正常的80端口、、注意目录都要填写迩的实际目录、然后运行nginx命令便可以成功运行了

 

Nginx的命令

nginx -s [ stop | quit | reopen | reload ]



 

参考文章:http://www.beechtreetech.com/ruby-on-rails-thin-and-nginx-on-windows

posted @ 2011-12-27 13:37  klobodnf  阅读(1761)  评论(0编辑  收藏  举报