What does upstream mean in nginx?

NginxConfiguration

Nginx Problem Overview


upstream app_front_static {
    server 192.168.206.105:80;
}

Never seen it before, anyone knows, what it means?

Nginx Solutions


Solution 1 - Nginx

It's used for proxying requests to other servers.

An example from http://wiki.nginx.org/LoadBalanceExample is:

http {
  upstream myproject {
    server 127.0.0.1:8000 weight=3;
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;    
    server 127.0.0.1:8003;
  }
 
  server {
    listen 80;
    server_name www.domain.com;
    location / {
      proxy_pass http://myproject;
    }
  }
}

This means all requests for / go to the any of the servers listed under upstream XXX, with a preference for port 8000.

Solution 2 - Nginx

upstream defines a cluster that you can proxy requests to. It's commonly used for defining either a web server cluster for load balancing, or an app server cluster for routing / load balancing.

Solution 3 - Nginx

If we have a single server we can directly include it in the proxy_pass directive. For example:

  server {
    ...
    location / {
      proxy_pass http://192.168.206.105:80;
      ...
    }
  }

But in case if we have many servers we use upstream to maintain the servers. Nginx will load-balance based on the incoming traffic, as shown in this answer.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiongdbView Question on Stackoverflow
Solution 1 - NginxPhil LelloView Answer on Stackoverflow
Solution 2 - NginxBen TaitelbaumView Answer on Stackoverflow
Solution 3 - NginxsatyanarayanaView Answer on Stackoverflow