Nginx-proxy: "worker_connections" directive is not allowed here

Created on 9 Nov 2017  路  3Comments  路  Source: nginx-proxy/nginx-proxy

TLDR: How can I update the nginx configuration to use 10k worker_connections? Is there a way to change the nginx configuration other than building another image based on this one (https://github.com/jwilder/nginx-proxy/issues/464)?

We are running this docker in production, and are now reaching the following error:

2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough
2017/11/09 15:04:38 [alert] 33#33: 1024 worker_connections are not enough

I would like to increase the number of worker_connections to a higher number, as stated in https://serverfault.com/questions/787919/optimal-value-for-nginx-worker-connections

I updated my_proxy.conf to:

$ cat my_proxy.conf
events {
  worker_connections 10000;
}
$ docker run -p 80:80 \
  -v /var/run/docker.sock:/tmp/docker.sock:ro \
  -v /home/cadesalaberry/Apps/industrial/setup/nginx/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro \
  jwilder/nginx-proxy

WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one
is being generated in the background.  Once the new dhparam.pem is in place, nginx will be reloaded.
forego     | starting dockergen.1 on port 5000
forego     | starting nginx.1 on port 5100
nginx.1    | 2017/11/09 15:08:42 [emerg] 37#37: "events" directive is not allowed here in /etc/nginx/conf.d/my_proxy.conf:3
forego     | starting nginx.1 on port 5200
forego     | sending SIGTERM to nginx.1
forego     | sending SIGTERM to dockergen.1

Then tried to put worker_connections at the root:

$ cat my_proxy.conf
events {
  worker_connections 10000;
}
$ docker run -p 80:80 \
  -v /var/run/docker.sock:/tmp/docker.sock:ro \
  -v /home/cadesalaberry/Apps/industrial/setup/nginx/my_proxy.conf:/etc/nginx/conf.d/my_proxy.conf:ro \
  jwilder/nginx-proxy
WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one
is being generated in the background.  Once the new dhparam.pem is in place, nginx will be reloaded.
forego     | starting dockergen.1 on port 5000
forego     | starting nginx.1 on port 5100
nginx.1    | 2017/11/09 15:08:56 [emerg] 32#32: "worker_connections" directive is not allowed here in /etc/nginx/conf.d/my_proxy.conf:3
nginx.1    | nginx: [emerg] "worker_connections" directive is not allowed here in /etc/nginx/conf.d/my_proxy.conf:3
forego     | starting nginx.1 on port 5200
forego     | sending SIGTERM to nginx.1
forego     | sending SIGTERM to dockergen.1

Most helpful comment

Can you provide more details on how one actually goes about implementing this workaround? I want to use all of nginx-proxy's normal configuration _except_ I want to increase the worker_connections count. Where is this nginx.conf file I need to replace? Is the file static or auto-generated when I create/destroy docker containers that nginx is monitoring?

All 3 comments

The reason it doesn't work is that conf.d/* is included from the "http" directive in the container-provided nginx.conf file.

You could either fork the repo or you could use docker's -v to map a replacement nginx.conf file over the default one.

Can you provide more details on how one actually goes about implementing this workaround? I want to use all of nginx-proxy's normal configuration _except_ I want to increase the worker_connections count. Where is this nginx.conf file I need to replace? Is the file static or auto-generated when I create/destroy docker containers that nginx is monitoring?

Hey I see that this is still unanswered and I was pretty frustrated that there was no easy option so I'll post my way of fixing this:
I copied the nginx.conf that comes from the docker image into a new file and placed it in the same dir as docker-compose file, changed worker_connections and mounted it as a volume in my docker-compose file.

version: "2"
services:
  nginx:
    restart: always
    image: jwilder/nginx-proxy:alpine
    labels:
      - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - "./nginx.conf:/etc/nginx/nginx.conf"

Seems to work.
Hope it helps.

Was this page helpful?
0 / 5 - 0 ratings