Adding CORS header in nginx-proxy appends the value rather than overrides it

回眸只為那壹抹淺笑 提交于 2020-01-16 14:28:31

问题


I'm trying to add a cors header using nginx proxy Docker container https://github.com/jwilder/nginx-proxy.

I've create a config file containing the line:

add_header 'Access-Control-Allow-Origin' '*' always

I've used a volume to pass this in through the docker-compose file at runtime so it appears at /etc/nginx/vhost.d/default

But the resulting header in the api response contains two values separated by a comma: http://myapi-domain.com, *

This makes cross-domain requests fail with the error: header contains multiple values but only one is allowed.

Think I'm following the documentation correctly...Is this a fault or is there a way to over-ride so there's only one value in the header?


回答1:


If anyone else is getting CORS errors with this nginx-proxy Docker, check the logs properly as this turned out to be a max_body_size error in the nginx. The browser saw it as a CORS error for some reason. max body size can be easily configured using the same method I used above to modify the headers



来源:https://stackoverflow.com/questions/58025213/adding-cors-header-in-nginx-proxy-appends-the-value-rather-than-overrides-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!