Disable 301 redirect for directory / use relative redirect / change scheme

Hi,

I have this setup
browser → ssl proxy → nginx
browser to ssl proxy is https only
ssl proxy to nginx is http only

now i browse to “exemple.com”, where aaa is a directory,
so nginx send back a 301 redirect with “Location:
exemple.com

Is it possible to send https instead of http (in Location),
or send a relative header, like “Location: /aaa/”,
or just disable this redirection (in my case it’s ok)

Thanks in advance
Etienne

On Thu, Aug 27, 2015 at 12:30 AM, Etienne Champetier
[email protected] wrote:

Is it possible to send https instead of http (in Location),
or send a relative header, like “Location: /aaa/”,
or just disable this redirection (in my case it’s ok)

see if proxy_redirect[1] fits your need.

http://nginx.org/r/proxy_redirect

2015-08-26 17:36 GMT+02:00 Edho A. [email protected]:

so nginx send back a 301 redirect with "Location:

nginx isn’t a proxy here, it’s a backend (no proxy_pass in my conf)
ssl proxy is a black box (not an nginx)

On 2015-08-26, 8:36 AM, Edho A. wrote:

so nginx send back a 301 redirect with “Location: exemple.com
nginx mailing list
[email protected]
nginx Info Page
use a rewrite 302 can easy help. If the client cant reach the intended
site (say due to internal network/firewalls) then you can also Proxy the
connection if needed.

here is how the 302 rewrite would look like:
rewrite ^ https://$hostname$request_uri? redirect;

You can also mix this with an if statement in case you only want
http://example.com/aaa” to be redirected to HTTPS and not everything

example:
if ($host = example.com) {
if ($uri = /aaa/) {
rewrite ^ https://$hostname$request_uri? redirect;
}
}

Something like that, this is untested but should work.
Keep in mind that using IF like this has a performance cost (though
small, it all depends on number of req/site load… something to keep in
mind)

Cheers,
Payam C.

On Thu, Aug 27, 2015 at 12:52 AM, Etienne Champetier
[email protected] wrote:

browser to ssl proxy is https only

see if proxy_redirect[1] fits your need.

Module ngx_http_proxy_module

nginx isn’t a proxy here, it’s a backend (no proxy_pass in my conf)
ssl proxy is a black box (not an nginx)

whoops right, sorry.

This seems to work:

if (-d $request_filename) { return 301 https://$host$uri/; }

2015-08-26 18:20 GMT+02:00 Edho A. [email protected]:

I have this setup
or just disable this redirection (in my case it’s ok)
whoops right, sorry.

This seems to work:

if (-d $request_filename) { return 301 https://$host$uri/; }

thanks, will try tomorrow

Please try something like that:

proxy_redirect http://$proxy_host/ $scheme://$host/;

Regards,
Biazus

Posted at Nginx Forum: