GrepBoard/매뉴얼
605 편 ·

nginx directive has no opening "{" 해결

·시험 환경 nginx 1.30.6 (Docker) · 2026-11·시험 범위 ↓·8 단계

nginx directive has no opening "{" 는 location·if·upstream 같은 블록 지시어가 { 대신 ; 로 끝났다는 뜻입니다. 줄 번호는 ; 가 있는 줄입니다.

output
2026/11/06 22:26:16 [emerg] 14#14: directive "location" has no opening "{" in /etc/nginx/nginx.conf:6nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/nginx.conf:6nginx: configuration file /etc/nginx/nginx.conf test failed

따옴표 안의 지시어(location)는 { 로 열리는 블록이 와야 하는데, 그 문장이 ; 로 끝났다는 뜻입니다. 이름이 찍힌 문장에 { ... } 를 붙이면 됩니다. 줄 번호는 location 이 있는 줄이 아니라 문장을 끝낸 ; 가 있는 줄이어서, 위 예에서는 한 줄 아래를 가리킵니다.

nginx 소스(ngx_conf_file.c, 1.30.6)는 블록 지시어가 { 가 아닌 것으로 끝나면 인자 개수를 세기도 전에 이 오류를 냅니다. 반대로 블록을 받지 않는 지시어에 { 를 쓰면 directive is not terminated by ";" 가 나옵니다.

[1] 오류에서 지시어 이름과 줄 번호를 읽습니다.

console
# nginx -t

include 한 파일에서 났다면 경로가 그 파일을 가리킵니다. 아래는 conf.d/api.conf 첫 줄이 location /api; 였던 경우입니다.

output
nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/conf.d/api.conf:1

[2] 이름이 찍힌 지시어를 찾아, 문장이 어디서 끝나는지 봅니다. 아래는 { 를 잊은 location 이고, 문장은 다음 줄의 ; 에서 끝나서 오류가 6번째 줄을 가리켰습니다.

/etc/nginx/nginx.conf
        location /api            return 204;

고치기 전에 원본을 사본으로 남기고, { 와 짝이 되는 } 를 함께 넣습니다.

/etc/nginx/nginx.conf
        location /api {            return 204;        }

[3] location 만의 오류가 아닙니다. 블록 지시어는 모두 같습니다. 한 줄짜리 if 가 흔한 예입니다.

/etc/nginx/nginx.conf
        if ($request_method = POST) return 405;
output
nginx: [emerg] directive "if" has no opening "{" in /etc/nginx/nginx.conf:5

if ($request_method = POST) { return 405; } 로 고칩니다. upstream backend 뒤에 { 없이 server 줄이 이어져도 upstream 이름으로 같은 오류입니다.

[4] { 가 분명히 있는데 같은 오류가 나면 앞에 # 가 있는지 봅니다. # 뒤는 줄 끝까지 주석이라 { 도 없는 것으로 읽힙니다.

/etc/nginx/nginx.conf
        location /api # {            return 204;        }
output
nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/nginx.conf:6

# 앞으로 { 를 옮깁니다(공식 문서: # 뒤의 줄 나머지는 주석).

[5] { 를 다음 줄에 둔 것은 원인이 아닙니다. 아래 설정은 nginx -t 를 통과했습니다.

/etc/nginx/nginx.conf
        location /api        {            return 204;        }
output
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful

[6] 문구가 다르면 { 가 빠진 자리가 다른 것입니다. location /api 바로 다음 줄이 } 이면 unexpected "}", http 가 파일의 마지막 줄이면 unexpected end of file 이 나옵니다.

output
nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:6nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/nginx.conf:2

닫는 } 가 모자란 경우는 unexpected end of file, expecting "}" 를 봅니다.

[7] 고친 뒤에는 검사하고, 통과하면 reload 합니다. nginx -t 는 파일만 검사하므로 reload 하기 전까지 실행 중인 nginx 는 예전 설정으로 동작합니다.

console
# nginx -t
output
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
console
# nginx -s reload; echo "reload exit=$?"
output
2026/11/06 22:26:18 [notice] 54#54: signal process startedreload exit=0

nginx 공식 문서는 설정을 다시 읽히려면 마스터 프로세스에 HUP 신호를 보내라고 하고, 마스터가 문법을 먼저 검사해 실패하면 변경을 되돌려 기존 설정으로 계속 동작한다고 적습니다.

[8] 검사를 건너뛰고 고장난 설정에 reload 를 해도 1.30.6 에서는 서비스가 멈추지 않았습니다. /ping 이 old 를 답하는 중에 location /ping 의 { 를 뺀 설정으로 reload 했습니다.

console
# nginx -s reload; echo "reload exit=$?"
output
2026/11/06 22:26:17 [emerg] 48#48: directive "location" has no opening "{" in /etc/nginx/nginx.conf:8nginx: [emerg] directive "location" has no opening "{" in /etc/nginx/nginx.conf:8reload exit=1
console
# curl -s localhost:8080/ping
output
old
console
# grep -c SIGHUP /tmp/error.log
output
0

종료 코드는 1 이고 에러 로그(시험에서는 /tmp/error.log)에 SIGHUP 이 없으니, 이 판에서는 신호를 보내기 전에 설정을 읽는 것으로 보입니다. control 문서에 없는 동작이고 다른 판은 확인하지 못했으니 nginx -t 를 먼저 하는 순서는 지킵니다.

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

#nginx#nginx-t#location#brace#config