Nginx跨域设置后返回内容不正确的原因?-灵析社区

元气满满才怪啊

nginx解决跨域,前端请求后返回的不是想要的内容? ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/37977a0cbf9e1907232bf00cd5e237a0.png) 正常返回应该是: ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/f9afcd3cdb874c037765c23895215d22.png) 而实际返回确实: ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/cd387378d0047232f2b52fdb04b184f7.png) ![image.png](https://wmprod.oss-cn-shanghai.aliyuncs.com/c/user/20240929/4220a3c6c0772041c78200fe48c4d749.png)

阅读量:122

点赞量:0

问AI
你这不是代理接口吗?为啥要指向到你的前端项目目录中? 给你一个例子,你参考以下: server { listen 80; server_name localhost; charset utf-8; location / { root 前端路径; try_files $uri $uri/ /index.html; index index.html index.htm; } location /api/ { proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass 后端接口地址; client_max_body_size 50m; } }