How to Enable CORS in Nginx


#1

nginx

TODOS

  • Fix Access to Font at 'http://example.com/example.ttf' from origin 'http://example.org' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.org' is therefore not allowed access.

Edit your /etc/nginx/sites-available/**example.com** and put code below to your server blocks location:

add_header Access-Control-Allow-Origin *;

Example

location ~* \.(css|eot|jpe?g|js|otf|png|svg|ttc|ttf|webp|woff|woff2)$ {
    add_header Access-Control-Allow-Origin *;
}

Now you can check on your site’s HTTP Header response. :+1: