1. 程式人生 > >在Amazon EC2上配置Thin+NginX+Rails全攻略 (Linux環境)

在Amazon EC2上配置Thin+NginX+Rails全攻略 (Linux環境)

upstream domain1 {
        server 0.0.0.0:3000;
        server 0.0.0.0:3001;
        server 0.0.0.0:3002;
    }

server {
            listen   80;
            server_name  www.realthematics.com;
            rewrite ^/(.*) http://domain.com permanent;
       }


server {
            listen   80;
            server_name www.realthematics.com;

            access_log /home/demo/public_html/railsapp/log/access.log;
            error_log /home/demo/public_html/railsapp/log/error.log;

            root   /home/demo/public_html/railsapp/public/;
            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 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://domain1;
                                           break;
                          }
            }

}

  寫好配置檔案要通知Nginx知道,使用: