nginx create rev proxy with multiple server

Goals

  1. Hide your app servers from public
  2. Manage your app servers
  3. Make scalable service

Tips

  1. Your app server will be hide by proxy
  2. In this example – app server should listen port 22222
  3. Port 22222 should be configured in firewall

/etc/nginx/sites-enabled/proxy

upstream app{
 ip_hash;
 server app1:22222;
 server app2:22222;
 server app3:22222;
}
server{
 server_name public.domain.com;

 location / {

 proxy_buffering off;
 proxy_buffers 200 512k;
 proxy_buffer_size 512k;

 proxy_pass http://app;

 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 }

}

/etc/hosts


xxx.xxx.xxx.xxx app1
xxx.xxx.xxx.xxx app2
xxx.xxx.xxx.xxx app3