gpt4 book ai didi

python - django 项目 nginx : connect() failed (111: Connection refused) while connecting to upstream ubuntu server on Digital Ocean

转载 作者:行者123 更新时间:2023-12-04 18:51:56 25 4
gpt4 key购买 nike

请帮帮我,我使用 django + gunicorn + nginx,但出现错误
nginx:连接到上游时连接()失败(111:连接被拒绝)
我认为问题是9000端口?如何解决这个问题呢?
502 Bad Gateway

/var/log/nginx/error.log

2015/05/07 04:57:28 [error] 11439#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 5.178.184.108, server: 45.55.254.196, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:9000/favicon.ico", host: "45.55.254.196"

sudo netstat -plntu
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 28846/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 946/sshd
tcp6 0 0 :::80 :::* LISTEN 28846/nginx
tcp6 0 0 :::22 :::* LISTEN 946/sshd

我的配置

/etc/nginx/sites-available/酒店
upstream app_server {
server 127.0.0.1:9000 fail_timeout=0;
}

server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;

client_max_body_size 4G;
server_name 45.55.254.196;

keepalive_timeout 5;

# Your Django project's media files - amend as required
location /media {
alias /home/django/hotel/media;
}

# your Django project's static files - amend as required
location /static {
alias /home/django/hotel/static;
}

# Proxy the static assests for the Django Admin panel
location /static/admin {
alias /usr/local/lib/python3.4/dist-packages/django/contrib/admin/static/admin/;
}

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}

/etc/init/gunicorn.conf
description "Gunicorn daemon for Django project"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [!12345]

respawn

setuid django
setgid django
chdir /home/django

exec gunicorn \
--name=hotel \
--pythonpath=hotel \
--bind=127.0.0.1:9000 \
--config /etc/gunicorn.d/gunicorn.py \
hotel.wsgi:application

/etc/gunicorn.d/gunicorn.py
from multiprocessing import cpu_count
from os import environ

def max_workers():
return cpu_count() * 2 + 1

max_requests = 1000
worker_class = 'gevent'
workers = max_workers()

最佳答案

你似乎还没有开始 unicorn 。既然你已经为它制作了一个初始化脚本,你应该做 sudo start gunicorn .

关于python - django 项目 nginx : connect() failed (111: Connection refused) while connecting to upstream ubuntu server on Digital Ocean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30098766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com