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

Popular posts from this blog

Android volley - avoid multiple requests of the same kind to the server? -

magento2 - Magento 2 admin grid add filter to collection -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -