nginx installation on docker container
拉取nginx image
1
docker pull nginx:latest
运行nginx
1
2
3
4
5
6docker run --name nginx \
-p 80:80 \
-v $HOME/docker/nginx/conf.d:/etc/nginx/conf.d \
-v $HOME/docker/nginx/html:/usr/share/nginx/html \
-v $HOME/docker/nginx/log:/var/log/nginx \
-d nginx:latest--name
指定docker容器名称-p
将容器的80端口映射到宿主机的80,格式主机端口
:容器端口
-v
$HOME/docker/nginx/conf.d:/etc/nginx/conf.d,映射nginx 配置目录-v
$HOME/docker/nginx/html:/usr/share/nginx/html,映射nginx 静态文件目录-v
$HOME/docker/nginx/log:/var/log/nginx 映射nginx日志目录-d
后台启动conf demo
在 $HOME/docker/nginx/conf.d:/etc/nginx/conf.d 新建以
.conf
结尾的配置文件,例如:test.conf1
2
3
4
5
6
7
8
9
10
11server {
listen 80;
server_name www.test.com;
location / {
proxy_pass http://test_server;
}
}
upstream test_server {
# 宿主机ip:port
server 192.168.2.42:6767;
}启动/停止nginx
1
2
3
4
5# 停止 nginx
docker stop nginx
# 启动 nginx
docker start nginx