如何使用 uwsgi-socket 与 nginx 进行负载平衡

How to load balancing with nginx using uwsgi-socket

我正在使用套接字文件通过 nginx 访问我的应用程序。 我的应用程序由三个侦听 8080、8081、8082 的服务器组成。 /etc/nginx/sites-available/config-file下的服务器配置低于

server {
    listen 8080 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name my-server-one;
    location / {
            include uwsgi_params;
            uwsgi_pass unix:/tmp/server_one.sock;
    }


server {
    listen 8081 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name my-server-two;
    location / {
            include uwsgi_params;
            uwsgi_pass unix:/tmp/server_two.sock;
    }

server {
    listen 8082 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
    server_name my-server-two;
    location / {
            include uwsgi_params;
            uwsgi_pass unix:/tmp/server_three.sock;
    }

我的问题是如何与上游应用负载平衡? 像下面的上游容器

upstream myserver {
    server localhost:8080;
    server localhost:8081;
    server localhost:8082;
}

谢谢,我终于找到了解决方案,想分享一下

为了设置 nginx 负载均衡器,我在上游添加了 .sock 文件并将上游传递给 uwsgi_pass

nginx load balancer with socket

upstream myserver {
   server unix:///tmp/server_one.sock;
   server unix:///tmp/server_two.sock;
   server unix:///tmp/server_three.sock;
}

/etc.nginx/sites-available/nginx-config 个文件在下面

server {
   listen 8080 default_server;
   listen [::]:80 default_server;
   root /var/www/html;
   index index.html index.htm index.nginx-debian.html;
   server_name my-server-one;
   location / {
        include uwsgi_params;
        uwsgi_pass myserver;
}

server {
   listen 8081 default_server;
   listen [::]:80 default_server;
   root /var/www/html;
   index index.html index.htm index.nginx-debian.html;
   server_name my-server-two;
   location / {
        include uwsgi_params;
        uwsgi_pass myserver;
}

server {
   listen 8082 default_server;
   listen [::]:80 default_server;
   root /var/www/html;
   index index.html index.htm index.nginx-debian.html;
   server_name my-server-two;
   location / {
        include uwsgi_params;
        uwsgi_pass myserver;
}