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 would like to serve static files with nginx. i get static pages via wget and the root of the directory tree is page protocol. ie for :

    └── index.html

i would like to be able to serve pages like this : to render

what is the nginx configuration for this ?

update: i tried this : rewrite ^(.+)://(.+)$ $1/$2 last; but it doesn't work

share|improve this question
i think it is only because i'm not allowed to use :// in url :-) – jney Oct 24 '10 at 22:27

If I understand you right then you are most likely looking for a forward proxy like Squid, Nginx is a reverse proxy and is not really made for situations like this.

share|improve this answer
maybe there are better tools but for now i would like to limit my project to nginx. are you sure there is no way to do it with nginx ? – jney Oct 24 '10 at 19:12
Research what a forward proxy is, if that is indeed what you need then no you cannot do it with Nginx as it is written to be a reverse proxy only. – Martin Fjordvald Oct 24 '10 at 23:23

As you can read in the location directive docs: The matching is performed against a normalized URI, after decoding the text encoded in the “%XX” form, resolving references to relative path components “.” and “..”, and possible compression of two or more adjacent slashes into a single slash.

You can prevent nginx from merging slashes at server block level with merge_slashes, although I would recommend caution doing such a thing and would generally advise against it.

Your regular expression does not match the normalized URI. You would need to use:

rewrite ^(.+):/(.+)$ $1/$2 last;

As a supplementary piece of advice, you might want to have a look at your regular expression to replace the generic . catch-all characters by more specific classes or sets, so its behavior is better defined.

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.