how to run nginx docker container with custom config?

前端 未结 3 451
误落风尘
误落风尘 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:06

    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
    
    0 讨论(0)
  • 2020-12-29 04:07

    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
    
    0 讨论(0)
  • 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"]
    
    0 讨论(0)
提交回复
热议问题