nginx 教程之 docker 化安装

nginx 教程之 docker 化安装

1.Why docker

因为要依赖很多lib,安装复杂,提高了学习和使用的难度,所以推荐使用docker 部署,可以快速迁移,快速部署,更多优点详见docker官网

2.部署

这里我们选择官方镜像,使用文档也可以在这个页面内找到。

使用完整nginx配置文件替换默认配置信息

1
docker run --name=nginx --net=host -v /host/path/nginx.conf:/etc/nginx/nginx.conf -d nginx:1.13.7-alpine

当然还可以继承默认配置,这样使用

1
docker run --name=nginx --net=host -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro -d nginx:1.13.7-alpine

3.nginx image默认配置

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
30
31
32

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


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

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;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf;
}

4.相关学习资源