Welcome! Log In Create A New Profile

Advanced

Re: Multiple Domain CORS

Andrey Oktyabrskiy
August 10, 2018 08:18AM
On 10.08.2018 14:38, Sathish Kumar wrote:
> Is there anyway to allow CORS domain like based on Host Origin.For
> Options, Get and other methods.
Something like this should do what you want:

location / {
include inc/cors_options.inc;
...
include inc/cors_headers.inc;
}

### /etc/nginx/inc/cors_options.inc
if ($request_method = 'OPTIONS') {
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Allow-Origin $cors_origin;
add_header Access-Control-Allow-Methods OPTIONS;
add_header Access-Control-Allow-Headers
$http_access_control_request_headers;
add_header Access-Control-Max-Age 86400;

add_header Content-Type 'text/plain; charset=utf-8';
add_header Content-Length 0;

return 204;
}

### /etc/nginx/inc/cors_headers.inc
add_header Access-Control-Allow-Credentials true always;
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Access-Control-Allow-Methods $cors_method always;
add_header Access-Control-Allow-Headers
$http_access_control_request_headers always;
add_header Access-Control-Max-Age 86400 always;

### /etc/nginx/sites-enabled/_map_cors_method
map $http_access_control_request_method $cors_method {
GET GET;
HEAD HEAD;
default OPTIONS;
}

$ cat /etc/nginx/sites-enabled/_map_cors_origin
map $http_origin $cors_origin {
https://domain.ru https://domain.ru;
...
default "";
}
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Multiple Domain CORS

Sathish Kumar August 10, 2018 07:40AM

Re: Multiple Domain CORS

Andrey Oktyabrskiy August 10, 2018 08:18AM

Re: Multiple Domain CORS

Andrey Oktyabrskiy August 10, 2018 08:48AM

Re: Multiple Domain CORS

Sathish Kumar April 12, 2019 09:50PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 313
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready