P
P
paramin2021-10-07 14:03:46
Nginx
paramin, 2021-10-07 14:03:46

How to open cors for 1 file on NGINX?

Hello. The nginx server has a json file.
When getting it by js. cors error, how to open 1 file for all domains?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2021-10-07
@paramin

Through location, refer to the desired file, and there, through add_header, add the necessary headers.
For example,

location = /myfile.json {
  add_header 'Access-Control-Allow-Origin' '*';
}

Keep in mind that the add_header declaration in the location block overrides the headers declared in the server block, so duplicate them if necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question