Docker 部署 Nginx

default

创建配置文件

1
2
3
4
mkdir ./nginx

vi ./nginx/nginx.conf

nginx.conf 写入以下内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
user  nginx;
worker_processes  auto;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

    server {
        listen       80;
        server_name  localhost;
        client_max_body_size 128M;

        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    }
}

创建 docker-compose.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
services:
  nginx:
    image: 'nginx:latest'
    container_name: nginx
    restart: always
    environment:
      - TZ=Asia/Shanghai
    volumes:
      - './nginx/nginx.conf:/etc/nginx/nginx.conf'
      - './nginx/html:/usr/share/nginx/html'
    ports:
      - 80:80
      - 443:443

启动

1
docker-compose -p project-name up -d

访问

http://127.0.0.1:80

Licensed under CC BY-NC-SA 4.0
Comments
  • Latest
  • Oldest
  • Hottest
No comment yet.
Powered by Waline v2.15.8
Gear(夕照)的博客。记录开发、生活,以及一些不足为道的思考……