4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

よし, じゃあVagrantで作った環境にnginxをぶちこんでやるぜ!

Last updated at Posted at 2018-08-13

季節外れのAdventCalendar2日目はいよーいスタート
前に勉強がてらに試しにやってみたやつの備忘録

目次

  • Vagrantの導入
  • CentOS7の作成
  • CentOSの設定
  • ポートフォワードの設定

1. Vagrantの導入

公式ページ様からダウンロードしインストールします.

なにも難しくない

バージョンの確認

-> % vagrant -v
Vagrant 2.1.2

2. CentOS7の作成

今回は, CentOSでやります.

仮想マシン用のディレクトリを適当に作成し移動します.

仮想マシンの初期化

-> % vagrant init centos/7

設定ファイルのVagrantfileができてるはずです.

起動する.

-> % vagrant up

初回は, Boxのダウンロードがあるので時間がかかります.

状態確認

-> % vagrant status
Current machine states:

default                   running (virtualbox)

The VM is running. To stop this VM, you can run `vagrant halt` to
shut it down forcefully, or you can run `vagrant suspend` to simply
suspend the virtual machine. In either case, to restart it again,
simply run `vagrant up`.

runningとでていれば正常に起動しています.

Vagrantfileのconfig.vm.network~のコメントアウトを外す

# Create a private network, which allows host-only access to the machine
  # using a specific IP.
   config.vm.network "private_network", ip: "192.168.33.10"

ssh-config内のホストを書き換えます.

-> % vagrant ssh-config --host 192.168.33.10
Host 192.168.33.10

これでssh接続できるようになります.

-> % ssh vagrant@192.168.33.10

3. CentOSの設定

これを参考に設定
https://qiita.com/ktkiyoshi/items/bf920b4df02d98b570e3

nginxは, 最新のやつが入らなかったので以下の方法で

/etc/yum.repos.d/nginx.repoに以下の設定を追加

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

インストール

$ sudo yum -y --enablerepo=nginx install nginx

4. ポートフォワードの設定

そのままだと外部から繋がらないのでVagrantfileのポートフォワードの設定をする.

# NOTE: This will enable public access to the opened port
   config.vm.network "forwarded_port", guest: 80, host: 10022

これでlocalhost:10022でマシン側につながるはずです.

4
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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?