此文档需在docker安装后操作
查找镜像
下载镜像
创建用于挂载nginx的目录
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
33
34
35
36
37
|
mkdir -p /home/docker/data/nginx
touch /home/docker/data/nginx/nginx.conf
vim /home/docker/data/nginx/nginx.conf #加入以下内容
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;
}
|
启动容器
1
2
3
4
5
|
docker run -itd -p 80:80 --name nginx \
-v /home/docker/data/nginx/conf:/etc/nginx/conf.d \
-v /home/docker/data/nginx/logs:/var/log/nginx \
-v /home/docker/data/nginx/nginx.conf:/etc/nginx/nginx.conf \
nginx /bin/bash
|
编写配置文件
在/home/docker/data/nginx/conf下创建xx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
vim git.conf #创建配置文件
#加入内容
server {
client_max_body_size 500m;
listen 80;
server_name XXXX.com;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://172.xx.xx.xx:xxx; # 这里设置你要代理的ip+端口
root /usr/share/nginx/html;
index index.html index.htm;
}
}
|
重启容器
启动nginx服务
1
|
docker exec -d nginx service nginx start
|
1
|
docker exec -d nginx nginx -s reload
|
Author
dylan
LastMod
2019-05-22
License
如需转载请注明文章作者和出处。谢谢!