LoginSignup
1
1

More than 5 years have passed since last update.

Vagrant で開発した Rails アプリケーションを Vagrant share でアクセスしてみよう

Posted at

環境

Vagrant 内の環境

  • rails がインストール済み
$ rails -v
Rails 4.1.5
  • nginx がインストール済み
$ nginx -v
nginx version: nginx/1.4.6 (Ubuntu)

Rails アプリケーションの配置

  • 今回はテスト用のアプリを作成する
$ pwd
/home/vagrant
$ rails new test_app
$ cd test_app

Nginx の設定ファイル編集

  • 設定ファイルを下記のように編集
/etc/nginx/nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/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;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;
#  デフォルトで読み込む設定ファイルを読まないようにする
#    include /etc/nginx/conf.d/*.conf;

    server {
# リクエストを受けるポート
        listen   80;
        server_name localhost;

        location / {
# 80 ポートで受けたリクエストを 3000 ポートに中継する
            proxy_pass http://127.0.0.1:3000;
        }
    }
}
  • 設定ファイルの再読み込み
$ sudo service nginx reload
$ sudo service nginx restart
  • うまく再読み込み出来ない場合は Vagrant を再起動する
# ホスト側で操作
$ vagrant halt
$ vagrant up

Rails アプリケーションのバックグラウンド実行と share

  • Rails アプリケーションをバックグラウンドで実行する
$ pwd
/home/vagrant/test_app
$ nohup rails s &
  • vagrand share を実行する
# ホスト側で操作
$ vagrant login
In a moment we'll ask for your username and password to Vagrant Cloud.
After authenticating, we will store an access token locally. Your
login details will be transmitted over a secure connection, and are
never stored on disk locally.

If you don't have a Vagrant Cloud account, sign up at vagrantcloud.com

Username or Email: 
Password (will be hidden): 
You're now logged in!

$ vagrant share
vagrant share
==> default: Detecting network information for machine...
    default: Local machine address: 192.168.33.10
    default: Local HTTP port: 3000
    default: Local HTTPS port: disabled
==> default: Checking authentication and authorization...
==> default: Creating Vagrant Share session...
    default: Share will be at: generous-mandrill-8127
==> default: Your Vagrant Share is running! Name: generous-mandrill-8127
==> default: URL: http://generous-mandrill-8127.vagrantshare.com

スクリーンショット 0026-09-07 15.27.29.png

  • Ctrl + c で vagrant share を終了する
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1