Score:0

redirect path of nginx from a proxy pass to another server

ru flag

I need to explain a problem. I need the output of the PATH content of an nginx reverse proxy to be sent to another domain that resides on another nginx server. Clear explanation: I have two linux servers "A" and "B", on the first server "A" I have a docker-like nginx with the following configuration:

server {
    listen       80;
    listen  [::]:80;
    server_name  example.com;
    location / {
        rewrite ^ https://$host$request_uri? permanent;
    }
}
server {
    listen       443 ssl http2;
    listen  [::]:443 ssl http2;
 
    server_name  example.com;
 
    ssl_certificate /etc/certs/x.pem;
    ssl_certificate_key /etc/certs/x.key;
    ssl_trusted_certificate /etc/certs/x.crt;
 
    location / {
      proxy_set_header        Host $host;
      proxy_set_header        X-Real-IP $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header        X-Forwarded-Proto $scheme;
 
      proxy_pass          http://docker-api;
      proxy_read_timeout  90;
    }
    location /path {
    ...Help!!
    }
}

**This server "A" correctly serves the URL example.com with the proxy pass the content of the docker called "docker-api". Now the problem comes: I want to redirect all the content that is offered in the path "example.com/path" to another domain called "test.com" that is located in server "B".

Server "B" has another nginx with default configuration:**

    listen       80;
    listen  [::]:80;
    server_name  test.com;
 
    location / {
        rewrite ^ https://$host$request_uri? permanent;
    }
}
server {
    listen       443 ssl http2;
    listen  [::]:443 ssl http2;
 
    server_name  test.com;
 
    ssl_certificate /etc/certs/x.pem;
    ssl_certificate_key /etc/certs/x.key;
    ssl_trusted_certificate /etc/certs/x.crt;
    location / {
    }
}

How do I make the content that is served on server "A" in the path "example.com/path" arrive intact at the url "test.com" and be able to serve it through this last url? I hope someone can help me, thanks in advance

us flag
To me it looks you need to use `proxy_pass` also there, where the destination is the other nginx server. What have you tried and how did it fail?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.