LoginSignup
0
0

More than 1 year has passed since last update.

[Nginxエラー]server-nameをDNS名にしたら起動できなかった。

Posted at

エラー発生状況

$ sudo service nginx start

をしたら、

Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

とエラーが発生。失敗したから、詳細は自分で見てね? とのこと。

$ 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
/etc/nginx/nginx.conf

サーバー名が長過ぎるので64以下に収めて。ということらしい。

/etc/nginx/conf.d/以下の設定ファイルのsever-nameに、ELBのDNS名を記述していたため、長過ぎると怒られてしまったようだ。64以上って、確かに大きい。

Elastic IPを取得するなど、サーバー名を短くするという手もあるが、
今回はserver-nameを変えずに対処してみる。

解決方法

ハッシュサイズが64よりも大きいため発生したエラーなので、設定ファイルの方で上限を変える。

$ sudo vim /etc/nginx/nginx.conf

で開き、

/etc/nginx/nginx.conf
keepalive_timeout  65;
# この下に以下を書き込む。
server_names_hash_bucket_size 128

仮に、サーバー名の長さを32以下に収めて、と言われた場合は、
128ではなく64を指定する。

今度は$ sudo service nginx startも成功した。

おわりに

「名前の長さ」というものも、今後考慮していこうと思います。

当然と言えば当然かもしれませんが、DNS名をそのまま使うのは控えめにしておいた方がいいのかもしれません。

参考
【Nginxエラー解決】Job for nginx.service failed because the control process exited with error code.
nginxでサーバ名が長いって怒られた
Nginxが起動しないエラーを解決したいです。

0
0
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
0