欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用nginx解决webstorm内置server调用本地api的跨域问题

程序员文章站 2022-08-10 15:20:15
webstorm内置的server在调用部署在本地不同端口的api时会产生跨域问题,在开发时可以用nginx代理解决跨域问题。 nginx.conf文件 server域中: l...

webstorm内置的server在调用部署在本地不同端口的api时会产生跨域问题,在开发时可以用nginx代理解决跨域问题。

nginx.conf文件 server域中:

listen 80;server_name localhost;root C:\Users\Administrator\Desktop\design;index index.html index.htm index.php;location /gP {????proxy_pass https://localhost:8080/gP;}

主要配置好root path和代理路径。

前端的请求url改为'/gP'+requestPath即可实现同域下请求。