242
upstream app_front_static {
    server 192.168.206.105:80;
}

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

automatix
  • 14,018
  • 26
  • 105
  • 230
gdb
  • 7,189
  • 12
  • 38
  • 36

3 Answers3

256

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.

Bahrom
  • 4,752
  • 32
  • 41
Phil Lello
  • 8,377
  • 2
  • 25
  • 34
  • 2
    why do you precise **`http {}`**? My conf has not this and it works. Just wondering – Olivier Pons Jun 16 '17 at 07:56
  • 9
    @OlivierPons maybe your config is `/etc/nginx/conf.d/default.conf` that is included in `/etc/nginx/nginx.conf`, which HAS `http {}` – srghma Mar 15 '18 at 19:47
56

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.

mikemaccana
  • 110,530
  • 99
  • 389
  • 494
Ben Taitelbaum
  • 7,343
  • 3
  • 25
  • 45
24

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.

McLan
  • 2,552
  • 9
  • 51
  • 85
satyanarayana
  • 367
  • 2
  • 4
  • 1
    Thanks. I was trying to `upstream` for one backend server, got too many open file errors etc. This is what I wanted for a test setup proxying towards Mojolicious. – Hugh Barnard May 13 '21 at 08:40