Nginx reverse proxy for multiple domains and subdomains

multiple-instancesnginxreverse-proxysubdomain

I have server running different sites and i need to config nginx reverse proxy for these domains, (example1.com, example2.com, test.example1.com), where dp I need to configure the domains in nginx for reverse proxy.

Best Answer

multiple server{} blocks and proxy_pass http://origin.server in location blocks.

For example:


server {
  test.example1.com;
  location / {
     proxy_pass http://origin.text.example1.com;
  }
}
server {
  server_name example1.com;
  location / {
     proxy_pass http://origin.example1.com;
  }
}
server {
  server_name example2.com;
  location / {
     proxy_pass http://origin.example2.com;
  }
}

nginx Beginner's Guide and Server names in nginx document will help you.

More complex configurations(including /etc/nginx/sites-enabled/.conf, /etc/nginx/sites-available/.conf) are available, but that relies on your distribution packages.