İçeriğe geç

Nginx Redirect with Header

We can use rewrite function for redirection but this function can’t redirect header variables. So we need to use proxy_pass and proxy_redirect functions.

For example

server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    server_name  api.example.com;

        location /endpoint1/ {
                proxy_pass https://endpoint1-service.example.com/;
                proxy_redirect https://endpoint1-service.example.com/  http://$host/endpoint1/;
        }

        location /endpoint2/ {
                proxy_pass https://endpoint2-service.example.com/;
                proxy_redirect https://endpoint2-service.example.com/  http://$host/endpoint2/;
        }

		#Different case
        location /endpoint3/ {
                proxy_pass https://endpoint3-service.example.com/;
		}
}
Tarih:Nginx

İlk Yorumu Siz Yapın

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir