I have an NGINX docker container with a an nginx.conf
file i copy into /etc/nginx/nginx.conf
. When i start the container/server, i get the following error:
2023/02/15 16:24:10 [emerg] 1#1: "server" directive is not allowed here in /etc/nginx/nginx.conf:1
nginx: [emerg] "server" directive is not allowed here in /etc/nginx/nginx.conf:1
I looked into it and there are a lot of posts about this error (granted, for different line numbers than "1"), but i don't understand what is wrong with this config. As far as i understand, the minimum "correct" nginx config should have this structure:
events {
...
}
http {
...
server {
...
}
}
with the events
part being actually optinal too. My config looks like this:
events {
worker_connections 4096; ## Default: 1024
}
http {
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
}
I also tried multiple versions, removing something in every iteration, down to just this (with and without events
part):
http {
server {
listen 80;
location / {
try_files $uri /index.html;
}
}
}
and it still gives the exact same error. I rebuild the container and copy the config after every change, so it cannot be that. What am i doing wrong?