I have been able to add a basic CORS support to my nginx server using the code provided in enable-cors.org. However this solution implies to copy and paste that code in every location block, and I have several locations like the following:
location /game1 {
alias /development/games/game1/output;
index index.html;
}
location /game2 {
alias /development/games/game2/output;
index index.html;
}
Is there a way to create a rule that includes add_header
outside the location
blocks?
Edit to clarify: I've tried the following
server {
listen 80;
server_name localhost;
charset UTF-8;
#access_log logs/host.access.log main;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
...
}
location /game1 {
alias /development/games/game1/output;
}
...
}
But it does not work:
2015/10/14 19:00:01 [emerg] 3464#7384: "add_header" directive is not allowed
here in C:\development\servers\nginx-1.7.9/conf/nginx.conf:43