GrepBoard/매뉴얼
605 편 ·

could not build server_names_hash 오류 해결

·시험 환경 nginx 1.30.6·1.31.8 (Docker) · Ubuntu 24.04 nginx 1.24.0 · 2026-10·시험 범위 ↓·5 단계

could not build server_names_hash 는 긴 server_name 때문입니다. http 블록에 server_names_hash_bucket_size 128 을 한 번만 넣습니다.

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

server_name 중 하나가 해시 칸(bucket)보다 길어서 nginx 가 시작하지 못하는 오류입니다. http 블록에 server_names_hash_bucket_size 128; 을 한 번만 넣으면 풀립니다. 끝의 64 는 지금 값이며, 공식 문서는 두 배 값(다음 거듭제곱)으로 올리라고 합니다.

[1] 문구를 보고 두 경우를 가릅니다. 이름이 길 때와 많을 때 나오는 문구가 다릅니다.

문구수준원인먼저 올릴 것
could not build server_names_hash, you should increase server_names_hash_bucket_size: 64[emerg] · 시작 실패긴 이름 하나server_names_hash_bucket_size
could not build optimal server_names_hash, you should increase either server_names_hash_max_size: 512 or server_names_hash_bucket_size: 64; ignoring server_names_hash_bucket_size[warn] · 시작은 됨이름이 아주 많음server_names_hash_max_size

공식 문서(Server names 의 Optimization 절)는 많은 쪽을 "another error message" 로 적지만, 1.30.6 에서 이름 3,000개로 시험하니 [warn] 이었고 nginx -t 는 성공했습니다. 문서의 문구도 could not build the server_names_hash 로 the 가 붙어 있어 실제 출력과 한 낱말 다릅니다.

[2] 가장 긴 이름을 찾습니다. 오류가 나는 동안에는 nginx -T 가 설정을 찍지 않으므로(검사가 실패하면 출력 0줄) 파일을 직접 읽습니다.

console
$ sudo nginx -T 2>/dev/null | wc -l$ sudo grep -RhE '^\s*server_name\s' /etc/nginx/nginx.conf /etc/nginx/conf.d/ /etc/nginx/sites-enabled/ 2>/dev/null | tr -s ' \t;' '\n' | grep -vE '^(server_name)?$' | awk '{ print length, $0 }' | sort -rn | head -n 3
output
055 preview-feature-branch-1234.staging.eu-west.example.com19 www.app.example.com15 app.example.com

-r 가 아니라 **-R** 입니다. Ubuntu 의 sites-enabled/ 항목은 sites-available/ 을 가리키는 링크인데, grep -r 은 폴더 안의 링크를 따라가지 않습니다. 같은 Ubuntu 시험에서 -r 로 돌리니 링크로 켠 사이트의 55자 이름이 빠지고 19 www.app.example.com 이 맨 위에 나왔습니다. 2>/dev/null 은 공식 nginx 이미지·nginx.org 패키지처럼 sites-enabled/ 가 없는 곳에서 No such file or directory 를 숨기려는 것입니다. 다른 경로를 include 한다면 그 경로도 넣습니다.

이 시험(64비트, 기본값 64)에서는 46자까지 통과하고 47자부터 위 오류가 났습니다. 이름 길이에 칸 안의 관리 정보가 더해지기 때문으로 보이며, 정확한 계산식은 공식 문서에서 확인하지 못했습니다. 미리보기·브랜치 이름으로 만든 긴 하위 도메인이 흔한 원인입니다.

[3] http 블록에 값을 넣습니다. Ubuntu 패키지의 /etc/nginx/nginx.conf 에는 이 줄이 주석으로 들어 있습니다.

output
23:	# server_names_hash_bucket_size 64;

주석을 풀고 값을 128 로 바꿉니다. 64 는 지금 기본값과 같아서 풀기만 하면 아무것도 바뀌지 않습니다.

/etc/nginx/nginx.conf
http {  server_names_hash_bucket_size 128;    ...}

conf.d/*.conf 는 http 블록 안에서 읽히므로 거기 써도 됩니다. 단, 두 곳에 쓰면 다른 오류로 바뀝니다. 같은 지시어를 두 번 쓴 결과입니다(Ubuntu 에서 주석을 푼 nginx.conf 와 conf.d 양쪽에 둬도 같은 directive is duplicate 가 났습니다).

output
nginx: [emerg] "server_names_hash_bucket_size" directive is duplicate in /etc/nginx/conf.d/default.conf:2nginx: configuration file /etc/nginx/nginx.conf test failed

한 곳만 남깁니다. 128 로도 모자라면 256 으로 올립니다.

[4] 이름이 많은 경우는 server_names_hash_max_size 를 먼저 올립니다. 공식 문서는 "이름 수에 가까운 값"을 먼저 시도하고, 그래도 안 되거나 시작이 너무 느릴 때만 bucket 을 올리라고 합니다. 이름 3,000개에서 4096 은 경고가 남았고 8192 에서 사라졌습니다.

/etc/nginx/nginx.conf
http {  server_names_hash_max_size 8192;    ...}
output
nginx: [warn] could not build optimal server_names_hash, you should increase either server_names_hash_max_size: 4096 or server_names_hash_bucket_size: 64; ignoring server_names_hash_bucket_size

위가 4096 일 때의 경고입니다. 경고 속 숫자가 지금 값이므로, 사라질 때까지 두 배씩 올립니다.

[5] 검사하고 다시 읽힙니다.

console
$ sudo nginx -t && sudo systemctl reload nginx
output
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful

검사가 실패하면 reload 는 실행되지 않고 지금 돌고 있는 nginx 는 옛 설정 그대로 남습니다. 되돌릴 때는 넣은 줄을 지우거나 다시 주석으로 만들고 같은 명령을 돌립니다.

같은 이름이 두 블록에 있어 생기는 경고는 conflicting server name … ignored, 포트를 잡지 못하는 오류는 bind() Address already in use를 봅니다.

Nginx 로그를 브라우저에서 바로 분석 ↗ — 아무것도 올라가지 않습니다.

#nginx#server_name#server_names_hash_bucket_size#nginx-t