当我将server名设置为DNS名称时,Nginx无法启动
错误发生情况
$ 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/下的配置文件的server-name中写入了ELB的DNS名称,导致被警告名称过长。确实,超过64字符是很长的。
尽管可以通过获取弹性IP等方式来缩短服务器名称,但这次我们将尝试不更改服务器名称来应对。
解决方式
由于哈希大小超过了64,因此发生了错误,因此需要在配置文件中更改上限。
$ sudo vim /etc/nginx/nginx.conf
打开,
keepalive_timeout 65;
# この下に以下を書き込む。
server_names_hash_bucket_size 128
如果被要求将服务器名称的长度限制在32个字符以内,那么应该选择64而不是128。
这一次,$ sudo service nginx start也成功了。
结束
「名字长度」这个问题,我将来也会考虑。
或许毫无疑问的是,可能最好还是谨慎地避免直接使用DNS名称。
参考
【解决Nginx错误】由于控制进程退出时返回错误代码,nginx.service任务失败。
nginx抱怨服务器名称太长。
我想解决Nginx无法启动的错误。