LoginSignup
0
1

More than 5 years have passed since last update.

Redhat7にnginxのインストールとバーチャルホストの設定

Last updated at Posted at 2017-02-17

インストール

# yum install nginx

# nginx -v
nginx version: nginx/1.10.2

バーチャルホストの設定

今後の規約として、

  • バーチャルホストの設定ファイルは、/etc/nginx/conf.dに、[ドメインのFQDN].confの名前で運用する。
  • バーチャルホストのドキュメントルートは、/var/www/vhosts/[ドメインのFQDN]とする。

上記のルールに従って、/etc/nginx/conf.dの下に、example.com.confという設定ファイルを作りました。

server {
    listen       80 default;
    server_name  ec2-xx-xxx-xxx-xx.xx-xxxx-2.compute.amazonaws.com;

    charset utf-8;

    location / {
        root   /var/www/vhosts/example.com;
        index  index.html index.htm;
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }

    location ~ /\.ht {
        deny  all;
    }
}

今後、このドメインをnginxのデフォルトサービスにしますので、defaultの設定をしています。

設定ファイルのシンタックスチェック

# nginx -t
nginx: [emerg] could not build server_names_hash, you should increase server_names_hash_bucket_size: 64
nginx: configuration file /etc/nginx/nginx.conf test failed

来ましたこれ。バーチャルホストの、server_nameが長いと怒られています。今回AWSのパプリックドメインをとりあえずそのまま使っているので、たしかに長いです。

で、エラーメッセージ通りに、nginx.confの、server_names_hashに、64を設定してあげてもやはり同じエラーが出ます。

なので、最終的に以下のようにhttpディレクティブの設定を修正しクリアしました。

http {
    server_names_hash_bucket_size 128;

確認。

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

成功!

デーモンの起動設定と、手動での起動

# systemctl enable nginx.service
# systemctl start nginx.service
0
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
0
1