Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 local folder /bar, and I want to be able access via

So I have the config like

rewrite  ^/foo/(.*)$ /bar/$1 last;

At the same time, I want to block public access to the real url /bar,

Then I add the config like

location ~* ^/bar{ return 404; }

But when I add this url into the config, the 1st config above not work, now both return 404

Anything I should fix in order to make the rewrite work?


share|improve this question
up vote 1 down vote accepted

Mark the "old" location as internal :

location /bar {
  # your /bar location directives

Nginx processes "internal" locations only when they happen as a result of error_page, rewrite, X-Accel-Redirect or SSI requests (see the full list in the documentation), otherwise it replies 404.

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.