I cannot connect to a flask app (searx search engine) served by nginx and uwsgi.

My web server shows "502 Bad Gateway nginx"

Here is my nginx error: error log: /var/log/nginx/error.log

[crit] 2688#2688: *4 connect() to unix:/run/uwsgi/app/searx/socket.sock failed 
(2: No such file or directory) while connecting to upstream,
client: 216.186.XXX.XXX, server searx.mysite.com, 
request: "GET / HTTP/1.1", 
upstream: "uwsgi://unix:/run/uwsgi/app/searx/socket.sock:", 
host: "searx.mysite.com"

So I can see that the socket.sock are not the same as the upstream.

here is my nginx.conf

user http;
worker_processes auto;
worker_cpu_affinity auto;

events {
    multi_accept on;
    worker_connections 1024;

http {
    charset utf-8;
    sendfile on;
    tcp-nopush on;
    tcp_nodelay on;
    server_tokens off;
    log_not_found off;
    types_hash_max_size 4096;
    client_max_body_size 16M;

    include mime.types;
    default_type application/octet-stream;

    keepalive_timeout 65;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log warn;

    include /etc/nginx/sites-enabled/*;

here is my searx.conf, the only place where I have specified where the .sock file is located:


server {
    listen 80;
    server_name searx.mysite.com;
    location / {
        include uwsgi_params;
        uwsgi_pass unix:/run/uwsgi/app/searx/socket.sock;
    root /usr/local/searx/searx-src/searx;
    location /static { }

When I look in my socket folder there is no file there...

ls -alh /run/uwsgi/app/searx/
total 0
drwxr-xr-x 2 searx searx 40 Jul 22 05:02 .
drwxr-xr-x 3 root  root  60 Jul 22 05:02 ..

The command I am using to run uwsgi is:

exec chpst -u http env LC_ALL=en_US.UTF-8 /usr/bin/uwsgi --master --die-on-term --emperor /etc/uwsgi/sites

the command I am using to run nginx:

exec chpst -u root /usr/bin/nginx -c /etc/nginx/nginx.conf -g "daemon off;"

here is my searx uwsgi file


project = searx
uid = searx
gid = searx
base = /usr/local/searx/searx-src

chdir = %(base)/%(project)
env = SEARX_SETTINGS_PATH=/etc/searx/settings.yml

disable-logging = false
workers = 2

chmod-socket = 666
vacuum = true

single-interpreter = true
master = true
plugin = python
lazy-apps = true
enable-threads = true

module = searx.webapp

route-run = fixpathinfo:

virtualenv = /usr/local/searx/searx-pyenv
pythonpath = %(base)

# NOTE: if I add or delete the next line there is no difference in output
socket = /run/uwsgi/app/searx/socket.sock

more digging: in the searx.ini I set disable-logging = false and found this in the /var/log/uwsgi/current log:

thunder lock: disabled (you can enable it with --thunder-lock
bind(): Permission denied [core/socket.c line 230]
Wed July 22 15:05:31 2020 - [emperor] curse the uwsgi instance searx.ini (pid: 3320)
Wed July 22 15:05:31 2020 - [emperor] removed uwsgi instance searx.ini

So there is definitely a problem with my searx.ini or how I am calling it?

I am not sure what other information you might need, but am happy to update the question as needed. I have been at this for days, so I would really appreciate any help you can provide.

  • Where are you specifying the socket that your uwsgi opens? Jul 22 '20 at 7:21
  • Please post the uwsgi ini file for the application in question. Jul 22 '20 at 11:09
  • @MichaelHampton I updated the original post with the searx uwsgi
    – posop
    Jul 22 '20 at 14:39
  • @TeroKilkanen I do not know where uwsgi://unix:/run/uwsgi/app/serax/socket.sock is being set for sure. I have tried my searx.ini file with and without the socket = /run/uwsgi/app/serax/socket.sock line, it does not affect the 502 error or the logging error.
    – posop
    Jul 22 '20 at 14:55
  • Is it serax or searx? Better check everything carefully for typos. Jul 22 '20 at 18:33

Found the issue. Answer for google posterity...

Of course it was file permissions:

  1. I added user searx to group http: usermod -a -G http searx
  2. I changed the searx directory to have http as it's group: chgrp -R http /usr/local/searx
  3. I made the searx directory writable by group: chmod -R g+w user/local/searx
  4. Did the same with my socket.sock folder: chgrp -R http /run/uwsgi/app/searx
  5. and made that folder writable by group: chmod -R g+w /run/uwsgi/app/searx
  6. Restart nginx and uwsgi.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.