nginx127.0.0.1与localhost跨域问题
前端vue,后端springboot,本地联调为解决跨域问题使用nginx反向代理,nginx配置如下:
1 | server { |
本地工程启动后,访问localhost:8090/aclui
,页面显示正常,但是后台接口调用全部失败,F12发现接口请求状态码返回200,但是response为:this request has no response data
后端工程控制台报错如下:
1 | 401 Unauthorized: [{"code":"401","content": { "unauthorized":"token is invalidate"}}] |
nginx error.log日志中有如下记录:
1 | 2021/11/04 18:08:44 [error] 2540#8504: *7200 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /aclrs/acl/option/set?option=2 HTTP/1.1", upstream: "http://127.0.0.1:8096//acl/option/set?option=2", host: "localhost:8090", referrer: "http://localhost:8090/aclui/view/acl/option/aclOptionCfg.html |
由于nginx中配置的是127.0.0.1
,实际访问的地址为localhost
,这种情况也会存在跨域的问题,造成this request has no response data
错误,将本地访问地址修改为127.0.0.1:8090/aclui
即可解决。
If the images or anything used in the blog infringe your copyright, please contact me to delete them. Thank you!