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 local folder /bar, and I want to be able access via http://www.example.com/foo.

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?

Thanks.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Mark the "old" location as internal :

location /bar {
  internal;
  # 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
add comment

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.