Skip to content

Instantly share code, notes, and snippets.

@JonasGao
Forked from sirsquidness/proxy.conf
Last active January 25, 2023 22:22
Show Gist options
  • Save JonasGao/89370dc9cf84f4bbc1131fce2e700635 to your computer and use it in GitHub Desktop.
Save JonasGao/89370dc9cf84f4bbc1131fce2e700635 to your computer and use it in GitHub Desktop.
How to have nginx proxy_pass follow upstream 302 redirects (Minimal, without Cache
server {
listen 80;
charset utf-8;
location / {
proxy_pass http://web;
proxy_intercept_errors on;
error_page 301 302 307 = @handle_redirects;
}
location @handle_redirects {
set $orig_loc $upstream_http_location;
proxy_pass $orig_loc;
}
}
@stopperbir
Copy link

Hi. I made a load balancer using Upstream. as follows.

*
*
*
   upstream appservers {
	least_conn;
        server srv1.domain.com:443;
        server srv2.domain.com:443;
    }
*
*
*
    server {
        listen 443 ssl http2;

        server_name domain.com:443;

        location /hls {	
		proxy_pass https://appservers/hls;
         }
    }
*
*
*

I set nginx.conf similar to above.

It's working fine now, but the main server domain.com:443 is heavily affected by live streams. How can I 302 forward this traffic to the edge servers?

So I want to direct every incoming request as a link to the end servers.

domain.com/hls/test.m3u8 > srv1.domain.com/hls/test.m3u8
domain.com/hls/test.m3u8 > srv2.domain.com/hls/test.m3u8
*
*
As. I want to distribute live streams to upstream servers.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment