LoginSignup
1
1

More than 3 years have passed since last update.

VirtualBoxで立ち上げた複数サーバーをnginxで振り分ける

Posted at

VirtualBoxでホストオンリー設定を行う。

以下の固定IPアドレスを設定したい

VM1: 192.168.56.101
VM2: 192.168.56.102

ホストマシンからpingで接続を確認

ping 192.168.56.101
ping 192.168.56.102

ホストマシンのIPアドレスを固定する

GUIから簡単に設定できるのでありがたい。
192.168.100.10とする。

nginxをインストール

sudo apt install -y nginx

proxy設定

/etc/nginx/sites-available/test.com
upstream test-1 {
    least_conn;
    server 192.168.56.101:443;
}
upstream test-2 {
    least_conn;
    server 192.168.56.102:443;
}

server {
    listen 80;
    listen [::]:80;
    server_name test1.com;

    location / {
        proxy_pass https://test-1;
    }
}

server {
    listen 80;
    listen [::]:80;
    server_name test2.com;

    location / {
        proxy_pass https://test-2;
    }
}

シンボリックリンク貼り付け

ln -s /etc/nginx/sites-available/test.com /etc/nginx/sites-enabled/test.com

再起動

sudo nginx -s reload

curlで接続確認

curl test1.com
curl test2.com
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