Django.fun

sock failed (111: Connection refused) while connecting to upstream using nginx + uwsgi for django

I'm making a django server. The server uses nginx and uwsgi.

The following error occurred in the server performance test.

2021/10/07 02:23:03 [error] 31#31: *9168 connect() to unix:/run/uwsgi/xxxx.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: xx.xxx.xxx.xx, server: xxxx.xxx.com, request: "GET /xxxx HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/xxxx.sock:", host: "xxxx.xxx.com"

I did some research on this problem and found that I could just adjust the uwsgi socket queue size. (Resource temporarily unavailable using uwsgi + nginx)

However, if I add the listen option to the uwsgi configuration, I get the following error:

2021/10/19 06:34:16 [error] 31#31: *69 connect() to unix:/run/uwsgi/xxxx.sock failed (111: Connection refused) while connecting to upstream, client: xx.xxx.xxx.xxx, server: xxxx.xxx.com, request: "GET /health-check HTTP/1.1", upstream: "uwsgi://unix:/run/uwsgi/xxxx.sock:", host: "xx.xxx.xxx.xxx"

Tried many ways to solve this problem but it didn't work.

I need help. Here is my nginx, uwsgi, etc configurations.

uwsgi.ini

[uwsgi]
project = xxxx
project_root = /xxxx
wsgi_path = xxxx_server_site
 
chdir = %(project_root)
module = %(wsgi_path).wsgi:application
 
master = true
processses = 4
listen = 4096 # Problem occurred after adding this option. If removed, it works normally.
 
socket = /run/uwsgi/%(project).sock
chmod-socket = 666
vacuum = true
 
logto = /var/log/uwsgi/%(project).log

/etc/nginx/conf.d/default.conf

server {
    listen 80;
    server_name xxxx.xxx.com;
 
    location / {
        include uwsgi_params;
        uwsgi_pass unix:/run/uwsgi/xxxx.sock;
        limit_except GET PUT { deny all; }
    }
}

/etc/nginx/nginx.conf

user    nginx;
worker_processes    auto;

error_log   /var/log/nginx/error.log notice;
pid         /var/run/nginx.pid;

events {
    worker_connections  4096;
}

http {
    include         /etc/nginx/mime.types;
    default_type    application/octet-stream;

    log_format  main    '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log   main;

    sendfile    on;
    #tcp_nopush on;

    keepalive_timeout   65;
    
    #gzip   on;

    include /etc/nginx/conf.d/*.conf;
}

docker-compose.yml

version: '3'
services:
    nginx:
        container_name: nginx
        build: ./nginx
        image: %{registry url}-%{nginx image name}
        restart: always
        ports:
          - "80:80"
        depends_on:
          - app
        volumes:
          - socket_share:/run/uwsgi
          - ./volumes/logs/nginx:/var/log/nginx
    app:
        container_name: app
        build: ./xxxx_app
        image: %{registry url}-%{app image name}
        restart: always
        command: uwsgi --ini uwsgi.ini
        volumes:
          - socket_share:/run/uwsgi
volumes:
    socket_share:

Does anyone know how to solve it? please.

Answers: 0