LoginSignup
4
3

More than 5 years have passed since last update.

conohaのロードバランサーを使う時のコツ

Last updated at Posted at 2017-12-27

conohaでロードバランサーを使う時、
メンテナンスが大変。
ということでコツを紹介。

nginxにサーバー初期ドメインを設定しておく

サーバーvps設定に逆引きホスト名がある。

v150-95-222-25.a0d1.g.tyo1.static.cnode.io

これが俗にいうサーバーの初期ドメイン。

nginxに設定


server {

listen 80;
server_name v150-95-222-25.a0d1.g.tyo1.static.cnode.io;
root /var/www/html/your.com/webroot/;
index  index.html index.php;



location / {
try_files $uri $uri?$args $uri/ /index.php?$uri&$args /index.php?$args;
}

location ~ \.php$ {
try_files      $uri =404;
fastcgi_pass   unix:/var/run/php-fpm.sock;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
include        fastcgi_params;
}

}

//他、独自ドメインやらいつもの設定。

こんな感じ。
これでサブドメインをロードバランサーを使って複数台運営しててもピンポイントでサーバーにアクセスすることができるようになる。

サーバーを立て直したい

外部DBを使っているとわざわざIPアドレスを指定しなければいけない。
サーバー削除 → サーバー構築ではIPアドレスが変わる。
そこで、サーバー再構築というメニューがあるので、それを使ってサーバーを立て直す。
そうすればIPアドレスを変更せずにサーバーの内容をまるっと再構築できる。

ちなみにサブドメイン設定をした nginx を他サーバーにコピーしていっても
正常に動作するので問題ない。

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