nginx redirect twice from https to http -
i have 2 servers, 1 has ssl , config this,
in server ssl certification(which https:// www.example.com):
location ~^/abc/.* { proxy_pass http://www.example.com:8214/ }
in server(which http:// www.anotherexample.com):
server { listen 8214; server_name www.anotherexample.com; rewrite ^/(.*)$ http://www.anotherexample.com:8080/$1 permanent; }
and after access https:// www.example.com/abc/api/getgroup
it can't redirect http:// www.anotherexample.com:8080/api/getgroup
anything wrong???
there couple of things improve configuration.
location ^~ /abc/ { proxy_pass http://www.example.com:8214$uri; #you should have other directives set here well. }
also, consider setting upstream
. then, server block:
server{ listen 8124; server_name www.anotherexample.com; rewrite ^/abc/(.*)$ http://www.anotherexample.com:8080/$1 permanent; } server{ listen 8080; server_name www.anotherexample.com; location ^~ /api/ { #your_config_here } }
the explanation:
in first location
block, shouldn't have .*
in expression. nginx match you. then, when you're proxying, can explicitly tell nginx send uri well.
next, you're sending uri www.anotherexample.com:8124
, includes /abc/
, want extract after that.
lastly, because you've rewritten point 8080
port, you'll need define separate server block this.
i don't know you're aiming achieve, proxying , redirects isn't necessary in cases, , might lead poor performance. consideration should take account you're sending unencrypted information anotherexample.com, which, if not on same local network, might security vulnerability.
Comments
Post a Comment