Welcome! Log In Create A New Profile

Advanced

Rewrite location and then proxy_pass

Posted by Szop 
Rewrite location and then proxy_pass
December 08, 2014 01:51AM
I'm having some difficulties rewriting a location to https, then asking if a specific cookie or IP is matched and then pass it to a http backend. For example, I need the /api location rewritten to https since the whole domain is just http and don't may be rewritten completely to https. My intention is something like this:

location ^~ /api {

rewrite https://$http_host$request_uri; (rewrite the location to https)

if ($iporcookiematches != 1) { (and then check if the ip or cookie matches)
return 403;
}

proxy_pass http://backend;
}

Does it make sense? Is it somehow possible?

Cheers,
Szop
Re: Rewrite location and then proxy_pass
December 08, 2014 08:25AM
Sorry,

this was a stupid question. Of course I need to redirect first to the SSL part and then check for the cookie or IP:

HTTP part:
location ^~ /api {

rewrite https://$http_host$request_uri; (rewrite the location to https)

}

HTTPS part:
location ^~ /api {

if ($iporcookiematches != 1) { (and then check if the ip or cookie matches)
return 403;
}

proxy_pass http://backend;
}

Please close this thread.

Cheers,
Szop
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 147
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready