1、主要作用
1、请求转发
浏览器 —> nginx(根据路径匹配) —> 不同的服务器
2、负载均衡
把请求平均的分担到不同的服务中去
3、动静分离
2、nginx.config
(1)修改 nginx 的默认端口,把 80 修改为 80
server {
listen 81;
server_name localhost;
}
(2)配置 nginx 的转发规则
在 http {} 里面创建配置
server {
# 监听端口
listen 9001;
# 主机
server_name localhost;
# 匹配路径 ~代表是正则匹配
location ~ /eduservice/ {
# 转发服务器地址
proxy_pass http://localhost:8001;
}
location ~ /eduoss/ {
proxy_pass http://localhost:8002;
}
}