What does the NGINX proxy_pass config do? Let's say for example I have a Django app that is hosted up on Amazon's EC2 services.
On EC2, let's say I have 1 load balancer in front of 2 nginx servers. The nginx servers point to the 4 django app servers that use Gunicorn as there WSGI server:
upstream my-upstream { server 12.34.45.65:8000; server 13.43.54.56:8000; server 13.46.56.52:8000; server 14.46.58.51:8000; } location / { proxy_pass } What is the proxy_pass? would it be the URL of the load balancer in this case?
2 Answers
Take a look at nginx's HttpProxyModule, which is where proxy_pass comes from. The proxy_pass docs say:
This directive sets the address of the proxied server and the URI to which location will be mapped.
So when you tell Nginx to proxy_pass, you're saying "Pass this request on to this proxy URL".
There's also documentation on upstream available:
This directive describes a set of servers, which can be used in directives proxy_pass and fastcgi_pass as a single entity.
So the reason that you use upstream for proxy_pass is because proxy_pass is expecting one URL, but you want to pass it more than one (so you use an upstream).
If your load balancer is in front of your nginx, your load balancer URL won't be in this config.
It should be: proxy_pass
nginx will load-balance all requests over your 4 djano+gunicorn instances (your my-upstream). The load-balancers will point to the nginx servers.
2