nginx配置允许跨域

nginx设置允许跨域

add_header 'Access-Control-Allow-Origin' '*'; #设置允许跨域
add_header 'Access-Control-Allow-Credentials' 'true'; #设置跨域是否需要认证(此处可不需要)
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; #设置允许通过跨域方法
add_header 'Access-Control-Allow-Headers' 'X-Requested-With'; #设置允许跨域的header

这一段可以放在http、server、location里面分别代表不同程度的跨域,其中Access-Control-Allow-Headers,Access-Control-Allow-Credentials可以不设置

你可能感兴趣的:(nginx配置允许跨域)