现象:一个前后端分离的项目,在本地联调的时候项目运行一切正常,但是在前端打完包之后放置到服务器上的时候,访问的时候接口出现了404?
解决途径:需要在后端apache或者nginx配置反向代理以指向正确的接口路径。
配置方式:
nginx配置:
网页查看接口路径===== http:://test.com/api.php/login
接口实际路径====http:://test.com/api/v1/login
nginx添加配置方式:
location /api.php{
proxy_pass http://test.com/api/v1;
}
apache配置:
网页查看接口路径===== http:://test.com/api.php/login
接口实际路径====http:://test.com/api/v1/login
nginx添加配置方式:
ProxyPass /api/ http://test.com/
ProxyPassReverse /api/ http://test.com/