Basic configuration of nginx based on docker

Time:2021-5-4

The directory structure is shown in the figure

Basic configuration of nginx based on docker

Docker-compose.yml configuration file

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 configuration file

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;
    }
}

This startup. Sh was written to delete the redundant container at that time, and was reserved for use

#! /usr/bin/bash
#Define a name variable
network_name="nginx_bridge"

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

if [ "$filterName" == "" ]; then
    #Create if it doesn't exist
    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

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]