how to run nginx docker container with custom config?

前端 未结 3 484
误落风尘
误落风尘 2020-12-29 03:36

I have a Dockerfile and custom nginx configuration file (in the same directory with Dockerfile) as follows:

Dockerfile:

FROM nginx

COPY nginx.conf /         


        
3条回答
  •  感动是毒
    2020-12-29 04:08

    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 the http 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 and nginx -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"]
    

提交回复
热议问题