Nginx reverse proxy redirect

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Nginx reverse proxy redirect

zakirenish
Hi guys,

I have a Nginx reverse proxy. How can I redirect it to the real server URL
when I download mp3 files in the reverse proxy.

For example:

normal reverse proxy request goes to backend node, but If the url contains
mp3, it redirects to another server.

Thanks.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,289072,289072#msg-289072

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx reverse proxy redirect

Francis Daly
On Wed, Aug 12, 2020 at 02:16:50AM -0400, Dr_tux wrote:

Hi there,

> I have a Nginx reverse proxy. How can I redirect it to the real server URL
> when I download mp3 files in the reverse proxy.

Make a location{} that handles mp3-file requests, and "return 301"
(or otherwise redirect) there.

> normal reverse proxy request goes to backend node, but If the url contains
> mp3, it redirects to another server.

You have something like

  location [normal reverse proxy request] {
    proxy_pass [somewhere]
  }

Add

  location [mp3 request] {
    return 301 [somewhere else]
  }

Fill in the bits in [square brackets] appropriately.

Depending on the full set of requirements, "~ mp3" or "~ mp3$" might be
a useful value for [mp3 request].

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx reverse proxy redirect

zakirenish
Thank you very much for this solution. but I have 3 mp3 servers. How can I
share requests equally? With 301, I can only send a request to a single ip
address.


Best.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,289072,289104#msg-289104

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx reverse proxy redirect

Francis Daly
On Thu, Aug 13, 2020 at 05:50:28PM -0400, Dr_tux wrote:

Hi there,

> Thank you very much for this solution. but I have 3 mp3 servers. How can I
> share requests equally? With 301, I can only send a request to a single ip
> address.

With 301, you invite the client to send a request to a single hostname.

You can set DNS up to make that be as many IP addresses as you like,
for example.

If you want within-nginx to issue 301 redirects to different
hostnames, you can use various ways, including perhaps
http://nginx.org/r/split_clients

But you might be happier at that stage, reverse-proxying the
mp3 requests rather than redirecting them -- set an "upstream"
(http://nginx.org/r/upstream) with your three "server"s, and proxy_pass
to the upstream -- that can also take care of some servers not always
being available, if that is a concern here.

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|

Re: Nginx reverse proxy redirect

zakirenish
That's perfect. Thank you.

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,289072,289230#msg-289230

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx