I'm trying to use regex capture functions for create an Access-Control-Origin header
.
So y have two main capture, one for the adress of website ( likehttp://example.com
)
and another for the port user (such as :4200
).
The idea is having this header : Origin: http://example.com:4200
My capture work for the first case but it seem to don't like the port.
I get Origin : http://example.com:
instead of Origin: http://example.com:4200
Here is my nginx config :
My guess is that Access-Control-Allow-Origin
don't understant numerical value.
if ($request_uri ~ ^/api/blabla/*){
set $public "1";
}
if ($http_origin ~* (https?:\/\/[^/]*(localhost|\.example.com))(:[0-9]+)?[^\w\d]) {
set $public "${public}1";
}
if ($public = "11"){
set $http_origin_regex $1$4;
add_header 'Access-Control-Allow-Origin' "$http_origin_regex";
}