Nginx

由 nginx uwsgi 服務的燒瓶應用程序返回 502

  • July 23, 2020

我無法連接到由 nginx 和 uwsgi 提供的燒瓶應用程序(searx 搜尋引擎)。

我的網路伺服器顯示“502 Bad Gateway nginx”

這是我的 nginx 錯誤:錯誤日誌:/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"

所以我可以看到socket.sock和上游不一樣。

這是我的 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/*;
}

這是我的 searx.conf,我指定 .sock 文件所在的唯一位置:

/etc/nginx/sites-enabled/searx.conf

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 { }
}

當我查看我的套接字文件夾時,那裡沒有文件……

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 ..

我用來執行 uwsgi 的命令是:

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

我用來執行 nginx 的命令:

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

這是我的 searx uwsgi 文件

/etc/uwsgi/sites/searx.ini

[uwsgi]
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

更多探勘:在我設置的 searx.ini中,在日誌disable-logging = false中找到了這個:/var/log/uwsgi/current

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

所以我的 searx.ini 或者我怎麼稱呼它肯定有問題?

我不確定您可能需要哪些其他資訊,但很高興根據需要更新問題。我已經在這幾天了,所以我非常感謝你能提供的任何幫助。

發現問題。回答Google后代…

當然是文件權限:

  1. 我將使用者 searx 添加到組 http: usermod -a -G http searx
  2. 我將 searx 目錄更改為 http 作為它的組:chgrp -R http /usr/local/searx
  3. 我使 searx 目錄可按組寫入: chmod -R g+w user/local/searx
  4. 對我的 socket.sock 文件夾做了同樣的事情: chgrp -R http /run/uwsgi/app/searx
  5. 並使該文件夾可按組寫入:chmod -R g+w /run/uwsgi/app/searx
  6. 重啟 nginx 和 uwsgi。

引用自:https://serverfault.com/questions/1026240