Docker - compose 배치 nginx

1727 단어
Docker - compose 배치 nginx
디 렉 터 리 구조
.
| -- conf.d
|    | -- nginx.conf
| -- dist
|    | -- index.html
|    | -- 50x.html
| -- compose-nginx.yaml
| -- startup.sh

compose-nginx.yaml
version: '3'

# docker network create nginx_bridge
networks:
  nginx_bridge:
    driver: bridge

services:
  nginx:
    image: nginx:stable-alpine
    #image: nginx:1.19.1-alpine
    container_name: nginx-alpine
    restart: always
    privileged: true
    environment:
      - TZ=Asia/Shanghai 
    ports:
      - 8080:80
      - 80:80
      - 443:443
    volumes:
      - /etc/localtime:/etc/localtime:ro
      #- ./conf/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./conf.d:/etc/nginx/conf.d
      - ./log:/var/log/nginx
      - ./dist:/opt/dist:ro
    networks:
      - nginx_bridge


nginx.conf
서버 설정 만 포함 합 니 다. 이 설정 은 용기 에 포 함 된 nginx. conf (주 설정) 입 니 다.

server {
        listen       80;
        server_name  192.168.31.202;
        client_max_body_size    1000M;
        #root         /opt/dist;

        #client_max_body_size 20M;

        # Load configuration files for the default server block.

        location / {
              root /opt/dist;
              index index.html;
        }

}


startup.sh
#! /usr/bin/bash
#         
network_name="nginx_bridge"

filterName=`docker network ls | grep $network_name | awk '{ print $2 }'`

if [ "$filterName" == "" ]; then
    #       
    docker network create $network_name
    echo "Created network $network_name success!!"
fi

docker-compose -f ./compose-nginx.yaml up -d
docker ps -a
docker logs -f nginx-alpine

좋은 웹페이지 즐겨찾기