在react中引入了setupProxy作为代理解决跨域问题,在本地可以做到了转发并访问外部接口,然后在把项目打包之后,放入nginx服务器上,再次请求外部接口,就会出现无法访问的情况,服务器上的报错是403。
PS:接口使用的人比较多,应该不会出现问题
react打包后代理失效
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
- 凉城┓.〆 2023-03-06 17:43关注
在生产环境,proxy是无效的
建议生产环境使用nginx解决跨域下边是ant-design-pro里边proxy的说明
/** * 在生产环境 代理是无法生效的,所以这里没有生产环境的配置 * The agent cannot take effect in the production environment * so there is no configuration of the production environment * For details, please see * https://pro.ant.design/docs/deploy */ export default { dev: { '/api/': { target: 'https://preview.pro.ant.design', changeOrigin: true, pathRewrite: { '^': '', }, }, }, test: { '/api/': { target: 'https://preview.pro.ant.design', changeOrigin: true, pathRewrite: { '^': '', }, }, }, pre: { '/api/': { target: 'your pre url', changeOrigin: true, pathRewrite: { '^': '', }, }, }, };
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥20 机器学习能否像多层线性模型一样处理嵌套数据
- ¥20 西门子S7-Graph,S7-300,梯形图
- ¥50 用易语言http 访问不了网页
- ¥50 safari浏览器fetch提交数据后数据丢失问题
- ¥15 matlab不知道怎么改,求解答!!
- ¥15 永磁直线电机的电流环pi调不出来
- ¥15 用stata实现聚类的代码
- ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
- ¥20 docker里部署springboot项目,访问不到扬声器
- ¥15 netty整合springboot之后自动重连失效