Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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:"); 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.


share|improve this question

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

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 (SAME ORIGIN)
  • JS is at (Access-Control-Allow-Origin:
share|improve this answer

Your Answer


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.