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 need to create proxy web using nginx. If I access the proxy_pass should be

Here is my configuration:

location / {
    proxy_pass $request_uri;
    proxy_cache_methods GET;
    proxy_set_header   Referer   "$request_uri";
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_ignore_headers  Cache-Control;
    proxy_hide_header Pragma;
    proxy_hide_header Set-Cookie;
    proxy_set_header Cache-Control Public;
    proxy_cache cache;
    proxy_cache_valid  200 10h;
    proxy_cache_valid  301 302 1h;
    proxy_cache_valid any 1h;

Here is the log error

2013/02/05 12:58:51 [error] 2118#0: *8 invalid URL prefix in "/", client:, server:, request: "HEAD / HTTP/1.1", host: ""
share|improve this question
What are you trying to accomplish? Are you sure nginx is what you need? – Ben. Feb 5 '13 at 12:12
I wan to create a service like Do you know other solution? – imastar Feb 5 '13 at 15:03
I guess your problem is that $request_uri begins with a '/' and is not a valid URL as such. So you need to find a way to remove it. You might want to have a look at This way you can remove the '/'. – Ben. Feb 5 '13 at 16:18

Try the map-Module of nginx to define variable the way you want:

map $request_uri $proxy_pass_target { 
  default ""; 
  ~^/(.+)$ $key;

Then you can use $proxy_pass_target in your proxy_pass directive instead of $request_uri.

Please note that I did not test if it works. Maybe you need to adjust the regex. Further documentation can be found here:

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.