1.下载并运行
# 下载
docker pull nginx
# 查看
docker images -a
# 运行
docker run --name nginx-test -p 8080:80 -d nginx
# 负载均衡运行
docker run -p 80:80 --net host --name mynginx -v /home/local/nginx.conf:/etc/nginx/nginx.conf -v /home/local/default.conf:/etc/nginx/nginx.d/default.conf --privileged=true -d nginx
2.修改配置
# 位置在 /etc/nginx/nginx.conf
# 复制一份到外边进行修改
docker cp nginx-test:/etc/nginx/nginx.conf /home/local
# 修改
vim /home/local/nginx.conf
3.配置文件的组成(三部分)
(1)全局块:
配置服务器整体运行的配置指令
比如 worker_processes 1;处理并发数的配置
(2)events 块:
影响 Nginx 服务器与用户的网络连接
比如 worker_connections 1024; 支持的最大连接数为 1024
(3)http 块 还包含两部分:
http 全局块 server 块3.1.全局块
4.Nginx配置实例-反向代理
5.Nginx+nacos配置负载均衡
5.1. /etc/nginx/nginx.conf配置
upstream nacos {
server 172.17.0.3:8848 weight=1 max_fails=2 fail_timeout=10s;
server 172.17.0.4:8848 weight=1 max_fails=2 fail_timeout=10s;
server 172.17.0.5:8848 weight=1 max_fails=2 fail_timeout=10s;
}
server{
listen 1111;
server_name 192.168.142.128;
location / {
proxy_pass http://nacos;
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_set_header REMOTE-HOST $remote_addr;
add_header X-Cache $upstream_cache_status;
add_header Cache-Control no-cache;
}
}
5.2.docker查看容器ip
docker inspect mysql5.7 | grep IPAddress
5.3.查看本机开放的端口
netstat -ntlp
网友评论