首先创建一个创建一个nginx 文件夹,并编辑docker-compose.yml

version: '2'
services:
  nginx:
    restart: always
    image: nginx 
    container_name: nginx #容器名称
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf # cong 映射
      - ./conf.d:/etc/nginx/conf.d	# conf.d 映射
      - ./conf/cert:/etc/nginx/cert	# ssl 证书映射 (不需要配饰ssl证书的可不需要)
      - ./log:/var/log/nginx 

在创建Makefile

.PHONY: pull up down

pull:
        docker-compose -f docker-compose.yml pull

up:
        docker-compose -f docker-compose.yml up -d

down:
        docker-compose -f docker-compose.yml down

创建好后在同级目录创建好映射的文件,以免启动的时候报错

mkdir conf
mkdir conf.d
mkdir log
mkdir conf/cert  #不需要配饰ssl证书的可不需要

创建config 配置文件

vim conf/nginx.conf
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;
}
vim /conf.d/default.conf
server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  192.168.13.128; # 可填写映射域名
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        proxy_pass http://192.168.13.128:8013; 
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

# 二级域名配置
server {
        listen       80;
        server_name  a.baidu.com; # 可填写映射域名

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        proxy_pass http://192.168.13.128:8014; 
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

启动

#启动
make up
#停止
make down