6

I currently have this rule in my nginx config:

location /tun {
proxy_pass         http://url.domain.com/mp3.mp3;
  proxy_set_header  X-Real-IP  $remote_addr;
}

Which i use for tunneling in a private project. However, i want to make it dynamic.

I am looking for something like this:

location /tun/$URL$ {
proxy_pass         $URL$;
  proxy_set_header  X-Real-IP  $remote_addr;
}

So users can type in their own url's like that.

I understand there are security flaws in this, but i really want to see this happening!

Thanks in advance!

1 Answer 1

6

Try this:

resolver 8.8.8.8;
location ~* ^/tun/(.+)$ {
    proxy_pass http://$1;
    proxy_set_header  X-Real-IP  $remote_addr;
}
Sign up to request clarification or add additional context in comments.

3 Comments

Gives me a 500 internal server error. I'll try play around with it though, thanks!
Add http://$1. If you are proxying to external domain, includes resolver 8.8.8.8;
Note this will fail if your URL contains spaces. NGINX has an unacknowledged bug where the incoming /url%20with%20spaces will result in $1 = /url with spaces and this is passed unencoded to proxy_pass as /url with spaces which will never work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.