[英]connection refused django gunicorn nginx
I am getting following error when running search feature on my site (search feature makes api request to my api server):在我的网站上运行搜索功能时出现以下错误(搜索功能向我的 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/"
The supervisord gunicorn is up, the mongodb is up, and nginx is up supervisord gunicorn 起来了,mongodb 起来了,nginx 起来了
I have the following /etc/nginx/sites-available/stocks_backend
:我有以下
/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;
}
I have tried things from Django gunicorn nginx (111: Connection refused) while connecting to upstream but when I remove http:// from the proxy_pass to the socket to proxy_pass unix:/etc/systemd/system/gunicorn.socket;
I have tried things from Django gunicorn nginx (111: Connection refused) while connecting to upstream but when I remove http:// from the proxy_pass to the socket to
proxy_pass unix:/etc/systemd/system/gunicorn.socket;
I get我明白了
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 socket独角兽插座
root@-droplet:~/stocks_backend# cat /etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
Change this line更改此行
proxy_pass http://unix:/etc/systemd/system/gunicorn.socket;
to至
proxy_pass unix:/etc/systemd/system/gunicorn.socket;
Essentially removing http://
because that's not how NGINX communicates with Gunicorn.基本上删除
http://
因为这不是 NGINX 与 Gunicorn 通信的方式。
Then, for the other problem that OP is getting, as of now OP doesn't have enough details.然后,对于 OP 遇到的另一个问题,到目前为止,OP 还没有足够的细节。
How can OP get more details about the problem? OP 如何获得有关该问题的更多详细信息? OP can setup NGINX error logs, as explained here .
OP 可以设置 NGINX 错误日志,如此处所述。 Then OP should be able to resolve the issue with the info from the logs.
然后 OP 应该能够使用日志中的信息解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.