3

I have problem with my nginx configuration. I want to add Access-Control-Allow-Origin header in nginx config, for one domain but for both http and https

I tried this configuration, but it doesn't work:

add_header 'Access-Control-Allow-Origin' "https://example.com http://example.com" always;

I get error response from browser:

The 'Access-Control-Allow-Origin' header contains multiple values 'https://example.com http://example.com', but only one is allowed. Have the server send the header with a valid value ?

asked Jun 22, 2020 at 9:20

1 Answer 1

4

Use nginx's $scheme variable

$scheme

request scheme, "http" or "https"

add_header 'Access-Control-Allow-Origin' "${scheme}://example.com" always;
answered Jun 22, 2020 at 11:22

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.