Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a server setup with nginx serving static content and proxy all PHP/dynamic requests to apache on 127.0.0.1

I'm building an API for my databases, and I need to allow clients by their origin (domain name), rather than just IP. Based on CORS rules.

So when I send an HTTP header header("Access-Control-Allow-Origin: www.client-requesting.myapi.com"); from my API server, I have to tell it which origin I allow, otherwise client side requests won't work to my API due to same-origin policy.

The question is how can I know which domain name (if any) called my API?

What should be the nginx and apache configuration to pass the origin parameter? I tried to google, and all I found is some possible solution with mod_rpaf, but I wanted to be sure.

Thanks!

share|improve this question

1 Answer 1

Same-Origin-Policy and CORS, as far as i understood, are server-based, not client-based, except when you have your API-Access-Scripts deployed on www.client-requesting.myapi.com.

so, what you are allowing with CORS is NOT, wherefrom API-Requests are allowed, but from which source an external script might access your API, e.g.

  • API is at api.my.com (SAME ORIGIN)
  • JS is at scripts.my.com (Access-Control-Allow-Origin: scripts.my.com)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.