Nginx 学习
# 安装docker
拉取镜像
docker pull nginx
创建配置文件目录
mkdir -p /www/docker/nginx-study/nginx/conf
拷贝配置文件
- docker run --name nginx01 -d nginx:latest
- 把容器中的nginx.conf文件复制到conf目录下
docker cp nginx01:/etc/nginx/nginx.conf /www/docker/nginx-study/nginx/conf
- 把容器中的default.conf文件复制到conf目录下
docker cp nginx01:/etc/nginx/conf.d/``default.conf /www/docker/nginx-study/nginx/conf
- 把容器中的default.conf文件复制到conf目录下
删除镜像
docker rm -f nginx01
重新运行容器
docker run -it -d --name nginx-study -p 9999:80 \
-v /www/docker/nginx-study/nginx/html:/usr/share/nginx/html \
-v /www/docker/nginx-study/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v /www/docker/nginx-study/nginx/conf/default.conf:/etc/nginx/conf.d/default.conf \
-v /www/docker/nginx-study/nginx/logs:/var/log/nginx \
nginx
1
2
3
4
5
6
2
3
4
5
6
# 负载均衡
http {
upstream upstream_name{
server 192.168.0.28:8001 weight=2; # 50%的访问机会
server 192.168.0.28:8002;
server 192.168.0.28:8002;
}
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://upstream_name;
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
上次更新: 2022/06/05, 20:31:36