天天看點

Ruby On Rails, Thin and Nginx on Windows

安裝thin:

gem install eventmachine --pre
gem install thin
           

啟動thin服務:

在rails的app目錄上輸入 thin start

配置nginx(nginx.conf):

worker_processes  1;
error_log  C:/StandAlone/nginx/logs/error.log;
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"';
 
    sendfile        on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    include C:/StandAlone/nginx/sites_enabled/*.txt;
}
           

其中include意思是從這個目錄時加載其它外部配置,按着配置檔案、在nginx目錄下建立sites_enabled檔案夾,接下來在裡面建立 mystandalone app.com.txt檔案、輸入以下内容:

upstream mystandaloneapp {
     server 127.0.0.1:3000;
 }
  
 server {
     listen       80;
     server_name  localhost;
     #charset koi8-r;
  
     access_log C:/StandAlone/www/mystandaloneapp.com/log/access.log;
     error_log  C:/StandAlone/www/mystandaloneapp.com/log/error.log;
     root       C:/StandAlone/www/mystandaloneapp.com;
     index      index.html;
  
     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    off;
         try_files C:/StandAlone/www/maintenance.html $uri $uri/index.html $uri.html @ruby;
     }
  
     location @ruby {
         proxy_pass http://mystandaloneapp;
     }
 }
           

這裡的配置就是把thin的3000端口轉化成正常的80端口,注意目錄都要填寫你的實際目錄,然後運作nginx指令便可以成功運作了

Nginx的指令

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

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

繼續閱讀