nginx


nginx

反向代理

image-20210111102656730

image-20210111102801707

如果路径中带有edu就访问8001

如果路径中带有vod就访问8002

负载均衡

image-20210111102849998

默认轮询算法

image-20210111102930328

image-20210111102941136

动静结合

image-20210111103000437

docker 实战

  1. 首先,pull nginx镜像
docker pull nginx:latest
  1. 进入docker 并且安装vim
首先运行一次,,确保没问题,
再把defatul.conf 复制出来
docker cp nginx:/etc/nginx/conf.d/defautl.conf .

进入容器docker exec -it nginx /bin/bash

cd /etc/apt 
cat > sources.list <
  1. 自定义docker网络
docker network create --driver=bridge --subnet=192.168.0.0/16 --gateway=192.168.1.0 mynet

# 查看docker 所有网络
docker network ls 
# 查看 docker内网情况
docker network inspect mynet 
  1. 运行nginx
docker run -it --name nginx1 -v /root/nginx/nginx1/default.conf:/etc/nginx/conf.d/default.conf -p 9001:80 --net mynet nginx
  1. 修改配置文件
# 这是docker 网络
        "ConfigOnly": false,
        "Containers": {
            "b842ce12f9f8d77fffcf827314ae6e7e2485778819f32ec8f6bb042b6eba4f32": {
                "Name": "tomcat1",
                "EndpointID": "9a7455e796a3c46ce7f902acf3e935a85fc61d9dc64f6d4529f392baffe3c2dc",
                "MacAddress": "02:42:c0:a8:00:01",
                "IPv4Address": "192.168.0.1/16",
                "IPv6Address": ""
            },
            "fb8b92e75d287db27b7c6ef150ce05c8a4a68beba8dfa78ae13cdfcb81c27f21": {
                "Name": "nginx1",
                "EndpointID": "67548a0cfbab7d5d18891b7188cbcb29835f9394c2ec783ad18113b0276e93b1",
                "MacAddress": "02:42:c0:a8:00:02",
                "IPv4Address": "192.168.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }



1 server {
2     listen       80;
3     server_name  192.168.0.2;   # nginx 的网络
4
5     location / {
6         proxy_pass http://192.168.0.1:8080;   # docker网络中,tomcat 的地址
7     }
8 }
  1. 测试

image-20210111114514928

image-20210111114519104.

都能访问,完成


文章作者: anlen123
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 anlen123 !
  目录