nginx 开启自定义header以及nginx开启跨域问题

1、nginx 开启自定义header

nginx是支持读取非标准的用户自定义header的,但是需要在http或者server下开启header的下划线支持。
添加设置:underscores_in_headers on;
代码如下

http{
		#开启非标准的用户自定义header
		underscores_in_headers on;
		...
}

2、nginx解决CORS跨域解决方案

在配置文件 server模块下面添加

add_header ‘Access-Control-Allow-Origin’ ‘*’;
add_header ‘Access-Control-Allow-Methods’ ‘GET,POST,OPTIONS’;
add_header ‘Access-Control-Allow-Headers’ ‘Origin,X-Requested-With,Content-Type,Accept,Authorization’;

代码如下

server{
	#跨域设置
    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'Origin,X-Requested-With,Content-Type,Accept,Authorization';
}
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐