nginxで複数サーバを稼働する

nginxの設定ファイルにserverディレクティブを複数立ててあげる。それぞれに設定を書いてあげればよい。

server {
    listen       443 ssl;
    server_name  goruchan.net;
    ssl_certificate ***/fullchain.pem; # managed by Certbot
    ssl_certificate_key ***/privkey.pem; # managed by Certbot

    access_log  ***/host.access.log  main;
    error_log ***/error.log debug;

    location / {
        root   ***/public;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
server {
    listen       443 ssl;
    server_name  goruchan.shop;
    ssl_certificate     ***/goruchan.shop.crt;
    ssl_certificate_key ***/goruchan.shop.key;

    access_log  ***/host.access.log  main;
    error_log ***/error.log debug;

    location / {
        root   ***/public;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

上記を書いたら、下記を実行して設定を反映する。

sudo nginx -s reload