0

i have my site domain.com in one server using nginx.

Every-time that someone hit [1] example.com/~username i need that show the content of [2] http://example2.com/~username/ that reside in other server.

But maintaining the original first domain name http://example.com/~username

so, when someone put [1] nginx request the content of [2] but maintaining [1] as domain name.

  • You are looking for a [reverse proxy](https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/) configuration. When acting as a reverse proxy, `example.com` will look like a mirror of `example2.com`. – Piotr P. Karwasz Feb 08 '20 at 05:27
  • You are looking for proxying. If a server answer to a request, „I‘m not responsible but ask my colleague https://worker.example.com“ it‘s called a redirect. If a server internally asks another server for the request and sends the given response to the client, it‘s called proxying. You can do that with Nginx. See http://nginx.org/en/docs/http/ngx_http_proxy_module.html – Jens Bradler Feb 08 '20 at 05:28
  • thanks for the clarification ... can i get some example... to have the picture clear ? – Zio Guillo Feb 08 '20 at 05:57

2 Answers2

0

You're looking to proxy the incoming request. You can do that in nginx with a similar config:

server {
listen 80;
server_name example.com;

location / {
    proxy_pass http://example2.com;
}
}

Here are the details on all of the settings: https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

Dbl0McJim
  • 91
  • 1
  • 5
0

Assuming you need to request other server for any username when your URI starts with /~, the very minimalistic variant is:

server {
    ...
    location ~ ^/(~.*) {
        proxy_pass http://example2.com/$1;
    }
}

In recent versions of nginx this will automatically set Host HTTP header to example2.com, but you may also need to set some other HTTP headers, see proxy_set_header for more information.

Ivan Shatsky
  • 2,726
  • 2
  • 7
  • 19