how to run nginx docker container with custom config?
As mentioned in the NGiNX documentation, upstream
is supposed to be defined in an http
context.
As mentioned in nginx
unkown directive “upstream
”:
When that file is included normally by
nginx.conf
, it is included already inside thehttp
context:
http { include /etc/nginx/sites-enabled/*;}
You either need to use
-c /etc/nginx/nginx.conf
or make a small wrapper like the above block andnginx -c
it.
In case of Docker, you can see different options with abevoelker/docker-nginx
:
docker run -v /tmp/foo:/foo abevoelker/nginx nginx -c /foo/nginx.conf
For a default nginx.conf
, check your CMD
:
CMD ["nginx", "-c", "/data/conf/nginx.conf"]
official nginx docker hub manual page:
docker run --name my-custom-nginx-container -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx
An example for adding gzip config:
docker run -v [./]gzip.conf:/etc/nginx/conf.d/gzip.conf nginx
or docker-compose:
version: '3'services: nginx: image: nginx volumes: - ./gzip.conf:/etc/nginx/conf.d/gzip.conf - ./html:/usr/share/nginx/html:ro