nginxでVirtualHostの設定

参考にした記事

nginx バーチャルホスト - nginx @ ウィキ - アットウィキ

nginxの設定について

nginx - 設定ファイル格納先(Ubuntu)

ざっくり手順

手順の補足

TKドメインの設定

f:id:ysirman:20190619235206p:plain

バーチャルホストの設定

/etc/nginx/sites-available/hogehoge.comの内容

server {
           #
           listen   80;
           #
           server_name www.hogehoge.com;
           #アクセスログの場所
           access_log /srv/hogehoge.com/public/log/access.log;
           #エラーログの場所
           error_log /srv/hogehoge.com/public/log/error.log;
           location / {
                       #ドキュメントルートのディレクトリ
                       root   /srv/hogehoge.com/public/;
                       index  index.html index.php;
                       }
           }
server {
           listen   80;
           server_name hogehoge.com;
           access_log /srv/hogehoge.com/public/log/access.log;
           error_log /srv/hogehoge.com/public/log/error.log;
           location / {
                       root   /srv/hogehoge.com/public/vh/;
                       index  index.html index.php;
                       }
           }

バーチャルホストの設定は、/etc/nginx/nginx.confではなく、/etc/nginx/sites-available/に書いて、/etc/nginx/sites-enabled/シンボリックリンクを作成するというのが習慣的な方法らしい。
nginxでsites-availableとsites-enabledを用いたバーチャルホストの設定 - YoshinoriN's Memento

/etc/nginx/nginx.confの中では、デフォルトで/etc/nginx/sites-enabled/*の設定を見るようになっている。
/etc/nginx/sites-enabled/の設定ファイルに対して、シンボリックリンクを作成していれば、/etc/nginx/sites-available/に作成した設定ファイルの中に、SSLの設定を書いてもOK!

注意点

存在しないファイルやディレクトリを指定するとnginx再起動の時にエラーになる。
nginx -tでエラー内容を確認して対応する。