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 am using nginx in front of several application servers as a reverse proxy. These upstream application servers also send requests to nginx, for example, direct nginx to server static assets.

In the nginx config, is it possible to distinguish requests from clients and those from upstream servers? For example, if I have a rule like below:

if ($uri ~* (\.jpg|\.png|\.css|\.js|\.html)$) { return 404; }

which intends that any direct request from clients for .html, .css, .js, etc should be rejected. How do I revise it to exclude the requests from upstream servers? Is there a variable or flag I can check to identify the source of requests?

I know I can put the above in individual location blocks, but that feels redundant/repetitive and potentially inefficient.

share|improve this question
It could be much simpler to have separate server block accessible only from upstream servers. But why do you want such unnatural way of serving static files? – Alexey Ten May 5 '14 at 5:38
@AlexeyTen, could you please give an example of how separate server block facilitate this situation? I serve the static files (mostly html files) this way to let the application server authorize access first based on various conditions. – skyork May 5 '14 at 12:30
If upstream and nginx are on the same machine, then just make server listening to localhost, it will not be available from outside. – Alexey Ten May 5 '14 at 12:32
Why loading html through nginx, why not read them from disk? – Alexey Ten May 5 '14 at 12:32

Your Answer


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

Browse other questions tagged or ask your own question.