在Amazon Web Service EC2上運行rails server

前提是ruby, rails, bundle等相關已經安裝好。或者直接選擇的ruby環境的EC2.

取一個git上的例子說明:

1.  git clone git://github.com/saasbook/hw2_rottenpotatoes.git

從Git上下載這個git代碼。

2. cd hw2_rottenpotatoes

到當前文件目錄

3. bundle install --without production

下載一系列的gem包。--without production part of the command causes the installer to ignore the
PostgreSQL gem for your local installation。(since that gem will cause problems if you're using a
development environment without PostgreSQL installed).
4. 你可以去查看下 db/seeds.rb  裏面的代碼,就是一些電影相關信息。

5. rake db:migrate     把所有rottenpotatoes移到本地數據庫。

6. rake db:seed       to seed your local database with the movies from the seed file.

7. rails server   啓動rails server



如果是在本地上跑,或者用VM, 那麼只需要打開 localhost:3000/movies  就能看到電影內容了。

問題如果是用的Amazon Web Service, EC2,   還需要在console management的界面左邊點 "Security groups", 增加一個"custom TCP" 協議, 端口是3000, source用默認的0.0.0.0/0。  這樣就可以開放aws-EC2的3000端口了。  然後用EC2的 public DNS加端口號訪問即可。  比如

ec2-183-71-2-31.us-west-1.compute.amazonaws.com:3000


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章