连接被拒绝django-gunicorn nginx



在我的网站上运行搜索功能时,我收到以下错误(搜索功能向我的api服务器发出api请求(:

2022/08/31 21:01:56 [error] 726#726: *23 connect() failed (111: Connection refused) while connecting to upstream, client: 11.111.111.111, server: api.mydomain.com, request: "GET /dividends/IBM/3/5 HTTP/1.1", upstream: "http://127.0.0.1:8001/dividends/IBM/3/5", host: "api.example.com", referrer: "example.com/"

监管程序gunicorn启动,mongodb启动,nginx启动

我有以下/etc/nginx/sites-available/stocks_backend:

upstream stocks_backend {
server 127.0.0.1:8001 fail_timeout=4s;
}
server {
server_name api.example.com www.api.example.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /root/stocks_backend;
}
location / {
include proxy_params;
proxy_pass http://unix:/etc/systemd/system/gunicorn.socket;
proxy_ssl_server_name on;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem; # managed by C>
ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem; # managed by>
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = api.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

listen 80;
listen [::]:80;
server_name api.example.com www.api.example.com;
return 404; # managed by Certbot
access_log /root/stocks_backend/log/nginx-access.log;
error_log /root/stocks_backend/log/nginx-error.log;
}

我在连接到上游时尝试过Django gunicorn nginx(111:连接被拒绝(的东西,但当我从proxy_pass中删除http://到proxy_pass unix:/etc/systemd/system/gunicorn.socket;的套接字时,我得到了

nano /etc/nginx/sites-available/stocks_backend
root@my-droplet:~/stocks_backend# sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.

gunicorn插座

root@-droplet:~/stocks_backend# cat /etc/systemd/system/gunicorn.socket 
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target

更改此行

proxy_pass http://unix:/etc/systemd/system/gunicorn.socket;

proxy_pass unix:/etc/systemd/system/gunicorn.socket;

本质上删除http://,因为NGINX与Gunicorn的通信方式并非如此。

那么,对于OP遇到的另一个问题,到目前为止,OP还没有足够的细节。

OP如何获得有关该问题的更多详细信息?OP可以设置NGINX错误日志,如下所述。然后OP应该能够使用日志中的信息来解决问题。

相关内容

  • 没有找到相关文章

最新更新