nginx如何配置跨域访问
要配置Nginx实现跨域访问,可以在Nginx的配置文件中添加以下内容:
http {
...
# 开启跨域要求支持
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';
...
}
这样配置后,Nginx将会添加相应的HTTP响应头,允许其他域名的要求跨域访问。
TOP