Di nginx.conf atau site-enabled/yourdomain.conf, tambahkan entyr berikut di dalam directive "location /"
location / {
# Simple requests
#
if ($request_method ~* "(GET|POST)") {
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Headers "Authorization, Origin, X-Requested-With, Content-Type, Accept, Connection, Accept-Language, Content-Language, Referer, Set-Cookie, Cookie";
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Expose-Headers "*";
}
# Preflighted requests
if ($request_method = OPTIONS ) {
add_header Access-Control-Allow-Origin "*" always;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, PUT, PATCH, DELETE";
add_header Access-Control-Allow-Headers "Authorization, Origin, X-Requested-With, Content-Type, Accept, Connection, Accept-Language, Content-Language, Referer, Set-Cookie, Cookie";
add_header Access-Control-Allow-Credentials true;
add_header Access-Control-Request-Headers "access-control-allow-credentials,content-type,set-cookie,cookie";
return 200;
}
...
...
}