I am trying to permit CORS for a cdn site but am struggling with the correct regex - I want to allow CORS for a specific location and all subfolders within that location :
location /cdn/lib/ {
add_header Access-Control-Allow-Origin *;
proxy_pass http://cdn_server_1;
}
This is only working for /cdn/lib
and not /cdn/lib/sub1/sub2/sub3
What is the correct syntax to allow CORS for all subfolders and files?
CodePudding user response:
You should use regex method in folder path to solve this problem. For example:
location ~ ^/cdn/(.*)$ {
add_header Access-Control-Allow-Origin *;
proxy_pass http://cdn_server_1;
}
This will make possible set headers for all cdn folders