1

I have nginx configured to proxy requests :

server  {
    listen      80;
    server_name proxy.mydomain.com;

    location /proxy {
        resolver 8.8.8.8;
        proxy_pass $args/;
    }
}

So I can make request like : http://proxy.mydomain.com/proxy?http://www.test.com

I'd like to control which domain is allowed to be proxied. I don't know how to do it without an if.

Bastien974
  • 1,824
  • 12
  • 43
  • 61

1 Answers1

0

I use / instead of ?, to proxy to www.test.com/xyz, it would be http://proxy.mydomain.com/proxy/www.test.com/xyz

server {
    listen 80;
    server_name proxy.mydomain.com;

    location ~ ^/proxy/(?<proxy_host>[^/]+)/(?<proxy_path>.+)$ {
        proxy_pass http://$proxy_host/$proxy_path?$args;
    }
}
Tan Hong Tat
  • 910
  • 5
  • 6