0

I need to create proxy web using nginx. If I access http://myweb.com/http://www.target.com/ the proxy_pass should be http://www.target.com/

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 "/http://www.target.com/", client: 108.59.8.83, server: myweb.com, request: "HEAD /http://www.target.com/ HTTP/1.1", host: "myweb.com"
3
  • What are you trying to accomplish? Are you sure nginx is what you need?
    – Ben.
    Feb 5, 2013 at 12:12
  • I wan to create a service like images.weserv.nl Do you know other solution?
    – imastar
    Feb 5, 2013 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 wiki.nginx.org/HttpMapModule. This way you can remove the '/'.
    – Ben.
    Feb 5, 2013 at 16:18

1 Answer 1

1

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

map $request_uri $proxy_pass_target { 
  default "http://myweb.com"; 
  ~^/(.+)$ $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: http://wiki.nginx.org/HttpMapModule

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .