(1)首先修改nginx 配置文件(nginx.conf)
upstream web-backend2{
server localhost:8011;(后端的地址和端口)
}
server {
listen 10001;(前端浏览器访问的端口)
server_name localhost;
location / {
root F:\intil\前端项目名称\dist;(前端项目的地址)
if ($query_string) {
expires max;
}
}
location ~ ^/(api|export) {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://web-backend2;
}
}
(2)假如登陆界面地址为127.0.0.1:10001 ,在前端访问后端的地址中,直接配置访问前端的地址即可,例如(http://127.0.0.1/10001/path)
总结:nginx 相当于tomcat服务器来启动前端项目,并转发请求。