Score:0

"server" directive is not allowed here in /etc/nginx/nginx.conf:1

gi flag

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?

Drifter104 avatar
ca flag
can you post the output of nginx -T
Furious Gamer avatar
gi flag
@Drifter104 I'm dumb, i DID make a mistake the last 2 hours rebuilding the docker image. It was a very subtle one, but basically i was rebuilding an image with the same name that was different than the one i was starting. Man, i had a feeling it is that but i rebuild it like 14 times to be sure. Classic. Sorry for wasting your time buddy!
Score:0
gi flag

As i wrote in the comment, the error indeed was in me rebuilding the image wrong, resulting in the changes never showing up in the NGINX config. I somehow build an image with the exact same name than the one i was starting, but it was a different one by ID internally somehow. TLDR; I'm dumb.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.