6

What is the NGinx 'directive not allowed here' error? I am trying to use NGinx for the first time, and within a Docker container, and I am using example configurations from other websites that seem to be correct configurations, but I get this error, no matter how I configure the nginx.conf file, and I don't know why.

2018/03/10 20:52:20 [emerg] 1#1: "user" directive is not allowed here in /etc/nginx/conf.d/nginx.conf:6 nginx: [emerg] "user" directive is not allowed here in /etc/nginx/conf.d/nginx.conf:6 

Link to my Github project branch (not master) demonstrating the problem.

I have Googled this error and see lots of answers suggesting it is a simple fix and I have tried them all.

For example, if I configure my nginx.conf file like so, I get the error:

# nginx.conf user nobody; 
3
  • 1
    I haven't used nginx or docker, but from the error message it looks like your file isn't the main nginx.conf (i.e. /etc/nginx/nginx.conf), but some additional config file that gets loaded elsewhere (/etc/nginx/conf.d/...). What does the main config file contain? Commented Mar 10, 2018 at 21:12
  • 2
    Is hub.docker.com/_/nginx what you're using? Because (under Complex configuration) that also says to install your config file as /etc/nginx/nginx.conf. Commented Mar 10, 2018 at 21:17
  • @melpomene Thank you , that fixed it. My updated repo is here: github.com/djangofan/docker-tomcat7-cluster Commented Mar 11, 2018 at 18:22

2 Answers 2

6

For anybody in my case (Docker + templates), the following might help.

I was getting this error:

nginx: [emerg] "user" directive is not allowed here in /etc/nginx/conf.d/default.conf:1 

The problem is that the template, at least in this official NGINX Docker image, is not meant to be a full config. It's included at the http block at /etc/nginx/nginx.conf file in the image:

user nginx; worker_processes auto; (...) http { (...) #gzip on; include /etc/nginx/conf.d/*.conf; } 

In my case, the solution was removing everything but my own http config.

Sign up to request clarification or add additional context in comments.

Comments

3

Thanks to a reply by @melpomene, 3 things fixed it:

  1. First, I had to copy my nginx.conf into the proper location according to Nginx 'complex config' documentation.
  2. I had to also copy (via docker run volume mount) an empty /etc/nginx/logs folder into place because it seems Nginx couldn't create the folder on its own?
  3. I had to supply a mime.types file.

My updated repo is here: https://github.com/djangofan/docker-tomcat7-cluster

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.