Nginx “server” directive is not allowed here: where the block goes
Updated 18 November 2026 · By Brent Alexis
Short answer: the server block is in the wrong place. Nginx only accepts it inside the http { } block, and the files in /etc/nginx/conf.d/ and /etc/nginx/sites-enabled/ are already read inside http. So a site file holds server blocks (and map or upstream) and nothing around them: no http { } wrapper, no events, no user. And don't paste it at the bottom of nginx.conf.
Tested on the official nginx Docker image (Nginx 1.30.7) and Debian 12's Nginx 1.22.1, with ProxyForge's own Config Generator output: 27 checks. How it's tested
- Where a site file goes
- Five ways to get this error
- The same error for map, location, proxy_pass, upstream
- A missing or extra brace
- An Apache config pasted into Nginx
- Test before you reload
- Nginx 1.30.7 security update
Where a site file goes
| Install | Put the site file here | Read from (inside http { }) |
|---|---|---|
| Debian, Ubuntu | /, then sudo ln -s / | include / |
| RHEL, AlmaLinux, Rocky, nginx.org packages, official Docker image | / | include / |
Those include lines sit inside the http { } block of nginx.conf: on the official image the include is line 31, inside the http { that opens on line 14; on Debian 12 they're lines 59 and 60, inside the http { on line 12. Whatever is in the included file is treated as if it were typed there, inside http. To see it on your server:
grep -n -E 'http \{|include' /etc/nginx/nginx.conf
The Config Generator's output starts with these same paths in its comments, and it passed nginx -t in both places: in conf.d on the official image, and in sites-available with the ln -s on Debian. Requests reached the app on both.
Five ways to get this error
Each one is a real nginx -t result from the lab, using the generator's reverse proxy output:
| What was done | What nginx -t said |
|---|---|
Pasted at the end of nginx.conf, after the http { } block | "map" directive is not allowed here in / |
The same, with WebSockets unticked (no map) | "server" directive is not allowed here in / |
nginx.conf replaced by the site file | "server" directive is not allowed here in / |
Site file wrapped in http { ... } | "http" directive is not allowed here in / |
A whole nginx.conf copied into conf.d | "user" directive is not allowed here in / |
A server block pasted inside another server block | "server" directive is not allowed here in / |
The first row catches people out: with WebSockets ticked, the generator's output starts with a map block, so the error names map, not server. Nginx always names the first line it can't place. The file name and line number after in tell you exactly where to look.
Fix: put nginx.conf back the way the package shipped it (from your backup), save the site in its own file in the folder from the table above, and remove any http { }, events { } or user lines from that file. If one server block ended up inside another, close the first block with } before the second one starts.
The same error for map, location, proxy_pass, upstream
“Not allowed here” always means a directive is in the wrong block. Each one belongs in a certain place:
| Directive | Goes in | What the lab got when it was elsewhere |
|---|---|---|
server, map, upstream | http (the top level of a site file) | map inside server: "map" directive is not allowed here ... :3; upstream inside server: "upstream" directive is not allowed here ... :3 |
location | server | A location block alone in conf.d: "location" directive is not allowed here ... :1 |
proxy_pass | location | Directly in server: "proxy_pass" directive is not allowed here ... :4 |
The WebSocket map is the one people move most often: it has to stay outside the server block, at the top of the site file. See Nginx WebSocket proxy not working.
A missing or extra brace
Brace mistakes give different messages, and they point at the end of the file rather than at the brace you missed:
- One
}missing:unexpected end of file, expecting "}" in /etc/nginx/conf.d/example.com.conf:26. Line 26 was the last line of the file. Count the opening and closing braces of each block. - One
}too many:unexpected "}" in /etc/nginx/conf.d/example.com.conf:27. This one does point at the extra brace.
A missing brace can also turn into the main error of this page: if a server block isn't closed and another server follows, the second one is inside the first.
An Apache config pasted into Nginx
An Apache <VirtualHost> block in an Nginx file doesn't say anything about Apache. Nginx gave:
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/example.com.conf:5
Apache lines don't end in ;, so Nginx reads the whole file as one unfinished line and runs out of file. If you see this on a short file with no semicolons, check that it's really an Nginx config. The Config Generator writes both: pick Nginx or Apache at the top.
On Debian 12's Nginx 1.22, the generator's default output stopped earlier with unknown directive "http2". That's a different problem, covered in Fix unknown directive "http2": tick Older Nginx in the generator.
Test before you reload
sudo nginx -t && sudo systemctl reload nginx
Every mistake on this page made nginx -t exit with 1 and print configuration file /etc/nginx/nginx.conf test failed, so the && stops the reload. In the lab, a reload with the broken file in place didn't take the site down: Nginx kept serving the old config. That also means your change silently isn't live until the test passes; see reload said OK, but my change didn't apply.
Nginx 1.30.7 security update
Nginx 1.30.7 (stable) and 1.31.9 (mainline) came out on 18 November 2026 with fixes for 10 vulnerabilities, including two use-after-free bugs and a memory-corruption bug in HTTP/2, a use-after-free in HTTP/3 and a buffer overflow when alias is used with try_files. Check your version with nginx -v. If you use a distro package, such as Debian's 1.22, install your distro's security updates; whether and when they carry these fixes is up to the distro. (Not lab-tested: from the nginx.org release announcement, checked 18 November 2026. This lab ran on 1.30.7.)
Generate an Nginx site file that goes straight into conf.d or sites-available →
How to use ProxyForge · FAQ: common errors · Guides · What's new · About