3
votes

I've read a tutorial on configuring nginx to reverse proxy

https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

In the configuration file, we use a sock

server {
    listen 80;
    server_name server_domain_or_IP;

    location / {
        include uwsgi_params;
        uwsgi_pass unix:/home/user/myproject/myproject.sock;
    }
}

Now, I'm reading other tutorials in order to do a load balancing with nginx

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-load-balancing https://www.upcloud.com/support/how-to-set-up-load-balancing/

However, it is strange that we no longer need the location of the sockets in the configuration file.

upstream backend  {
  server backend1.example.com;
  server backend2.example.com;
  server backend3.example.com;
}

server {
  location / {
    proxy_pass  http://backend;
  }
}

Is it normal or is there a specificity with uwsgi ?

Will I need to add the location of the sockets in the configuration file or are they not needed ? If so, how ? On the server, do I need to create a socket ? If the configuration file does not specify the location of the socket, how will it be used ?

EDIT : I've also read a tutorial when socket are defined this way

socket = :5000

and the socket is not mentionned in the configuration file.

Is this the way to do it when load balancing ?

1
any update on this? I have the same question - florin
@florin I stumbled into the same problem and this answer really nicely covers the problem (although for Kubernetes): stackoverflow.com/a/44533608/1039281 - stx
you can define as server a socket e.g. server unix:/home/user/myproject/myproject.sock; instead of an ip or domain and I have also seen that prefix http:// is not needed in http://backend. Still I haven't made it work so it is possible that you will run into issues. - kon psych

1 Answers

1
votes

You need to define 'backend' somewhere. Try something like this:

upstream backend {
    least_conn;  # this is your load balancing strategy, see http://nginx.org/en/docs/http/load_balancing.html#nginx_load_balancing_methods

    server 172.16.10.10;
    server 172.16.10.12;
}

Now I see you use socks. I never used this, so not sure how you would define those inside backend. The example I showed here is for load balancing in front of http servers.