nginx配置跨域的步骤
1.在nginx.conf配置文件中添加以下代码:
location /api/ {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
if ($request_method = 'OPTIONS') {
return 204;
}
}
其中,/api/为需要跨域的接口路由。
2.重启Nginx服务,使配置生效。
原文地址: https://www.cveoy.top/t/topic/bM2l 著作权归作者所有。请勿转载和采集!