配置搜索Url,下图是Nginx搜索转发流程图:
用户请求/course/search时Nginx将请求转发到nuxt.js服务,nginx在转发时根据每台nuxt服务的负载情况进行转 发,实现负载均衡。
本教程开发环境Nuxt.js服务和www.xuecheng.com虚拟机主在同一台计算机,使用同一个nginx,配置如下:
[mw_shl_code=applescript,true]#前端门户课程搜索
location ^~ /course/search {
proxy_pass http://dynamic_portal_server_pool;
}
#后端搜索服务
location /openapi/search/ {
proxy_pass http://search_server_pool/search/;
}
#分类信息
location /static/category/ {
proxy_pass http://static_server_pool;
}
[/mw_shl_code]
dynamic_portal_server_pool配置如下 :
[mw_shl_code=applescript,true]#前端动态门户
upstream dynamic_portal_server_pool{ server 127.0.0.1:10000 weight=10;
}
#后台搜索(公开api) upstream search_server_pool{
server 127.0.0.1:40100 weight=10;
}
[/mw_shl_code]其它配置:
[mw_shl_code=applescript,true]#开发环境webpack定时加载此文件 location ^~ /__webpack_hmr { proxy_pass http://dynamic_portal_server_pool/__webpack_hmr;
}[/mw_shl_code]
[mw_shl_code=applescript,true]#开发环境nuxt访问_nuxt location ^~ /_nuxt/ { proxy_pass http://dynamic_portal_server_pool/_nuxt/;
}[/mw_shl_code]
在静态虚拟主机中添加:
[mw_shl_code=applescript,true]#学成网静态资源 server { listen
91; server_name localhost;
#分类信息
location /static/category/ {
alias F:/develop/xuecheng/static/category/;
} ...[/mw_shl_code]