基于docker的nginx基础配置

目录结构, 如图

基于docker的nginx基础配置_第1张图片

docker-compose.yml配置文件

version: '3.1'

services:
  nginx:
    image: daocloud.io/library/nginx:1.14
    container_name: nginx
    restart: always
    privileged: true
    environment:
      - TZ=Asia/Shanghai
    ports:
      - 999:80
      - 998:443
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ./conf:/etc/nginx/conf.d
      - ./logs:/var/log/nginx
      - ./html:/opt/dist:ro
    networks:
      - nginx_bridge

networks:
  nginx_bridge:
    driver: bridge

conf/nginx.conf配置文件

server {
    listen       80;
    server_name  thatsmycicd;
    gzip  on;
    gzip_buffers 32 4k;
    gzip_comp_level 6;
    gzip_min_length 200;
    gzip_types text/css text/xml application/x-javascript;

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

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /opt/dist;
    }
}
这个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 ./docker-compose.yml up -d
docker ps -a
docker logs -f nginx

你可能感兴趣的:(docker,nginx)