我有一个包含2个partitons的项目(http://backend.domain.com-使用Symfony 3.4的后端,http://frontend.domain.com-使用AngularJs 5,nginx,php7.2的前端)。
我在配置中使用了“ nelmio / cors-bundle”:“ ^ 1.5”
nelmio_cors:
defaults:
allow_credentials: false
allow_origin: []
allow_headers: []
allow_methods: []
expose_headers: []
max_age: 0
hosts: []
origin_regex: false
paths:
'^/api':
forced_allow_origin_value: '*'
origin_regex: true
allow_origin: ['*']
allow_headers: ['*']
allow_methods: ['POST', 'PUT', 'GET', 'DELETE', 'OPTION']
max_age: 3600
hosts: ['^/']
当角度发送带有标题*** Content-Type:application / json ****的OPTION请求时,响应为
XMLHttpRequest无法加载http://backend.nearist.com/security/login。对预检请求的响应未通过访问控制检查:“ Access-Control-Allow-Origin”标头包含多个值“ null,*”,但仅允许一个。因此,不允许访问来源“ http://frontend.nearist.com”。
在后端,我在CorsListener.php中看到情况
// perform preflight checks
if ('OPTIONS' === $request->getMethod()) {
$event->setResponse($this->getPreflightResponse($request, $options));
return;
}
什么是问题,后端配置或角度请求缺少标头?