2020-01-05 nginx反向代理与负载均衡实践
2020-01-06 本文已影响0人
月圆星繁
实例一
使用nginx反向代理,访问www.123.com 直接跳转到127.0.0.1:8080
操作
a) 本地的host文件中做映射关系: www.123.com 127.0.0.1
b) 在nginx的配置文件中做如下处理:
server {
listen 80;
server_name www.123.com;
location / {
proxy_pass http://127.0.0.1:8080;
index index.html index.php index.htm;
}
}
实例二
使用nginx反向代理,根据访问的路径跳转到不同的端口的服务中,nginx监听端口9001:
访问 http://127.0.0.1:9001/edu/ 跳转到127.0.0.1: 8088
访问 http://127.0.0.1:9001/new/ 跳转到127.0.0.1: 8066
操作
a) 前置操作:
b) 代码部分:
server {
listen 9001;
server_name localhost;
location ~ /edu/ {
proxy_pass http://127.0.0.1:8088;
}
location ~ /new/ {
proxy_pass http://127.0.0.1:8066;
}
}
负载均衡
实例待补充...
实例待补充...