我已经运行了我的bin bash gunicorn文件,是的,它引导我的13个工人没有错误,但是:
除此之外,如果我正确理解了事情的工作原理,这段代码(IP更改)应该可以让我看到我的网站,因为gunicorn正在取代runserver
[2023-12-20 21:50:45 +0100] [35586] [INFO] Starting gunicorn 21.2.0
[2023-12-20 21:50:45 +0100] [35586] [DEBUG] Arbiter booted
[2023-12-20 21:50:45 +0100] [35586] [INFO] Listening at: unix:/home/boards/run/gunicorn.sock (35586)
[2023-12-20 21:50:45 +0100] [35586] [INFO] Using worker: sync
[2023-12-20 21:50:45 +0100] [35591] [INFO] Booting worker with pid: 35591
字符串
但我得到一个服务器错误500问题:我应该能够看到我的网站通过该命令?如果是的,为什么我看不到它?
然后ginx简单地调用那个gunicorn文件,所以,如果我还没有能够看到我的web,nginx根本不会帮助。这意味着gunicorn尽管引导worker也没有任何好处?Supervisor也不会帮助,它只是在gunicorn关闭时重新启动。
对于好奇的人,我的gunicorn文件是这样的(网址已更改)
NAME="boards" # Name of the application
DJANGODIR=/home/boards/me # Django project directory
SOCKFILE=/home/boards/run/gunicorn.sock # we will communicte using this unix socket
USER=boards # the user to run as
GROUP=boards # the group to run as
NUM_WORKERS=13 # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=estate.settings # which settings file should Django use
DJANGO_WSGI_MODULE=estate.wsgi
# WSGI module name
PATH_HOME="/home/boards"
PATH_ENV="$PATH_HOME/venv"
echo "Starting $NAME as `whoami`"
# Activate the virtual environment
cd $DJANGODIR
source $PATH_ENV/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
型
错误内容如下:
request: "GET /.env HTTP/1.1", upstream: "http://unix:/home/boards/run/gunicorn.sock:/.env", host: "222.222.22.22"
2023/12/20 21:38:29 [crit] 35388#35388: *12 connect() to unix:/home/boards/run/gunicorn.sock failed (2: No such file or directory) while connecting to upstream, client: 111.111.111.111, server: myweb.com, request: "POST / HTTP/1.1", upstream: "http://unix:/home/boards
型
/run/gunicorn.sock:/",主机:“222.222.22.22“
我的nginx是:
upstream app_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a
# single worker for timing out).
server unix:/home/boards/run/gunicorn.sock fail_timeout=0;
}
server {
listen 80;
# listen[::]:80;
server_name myweb.com 111.111.111.111 www.myweb.com; # here can also be the IP address of the server
keepalive_timeout 5;
client_max_body_size 4G;
access_log /home/boards/logs/nginx-access.log;
error_log /home/boards/logs/nginx-error.log;
location /static/ {
alias /home/boards/staticfiles/;
}
# checks for static file, if not found proxy to app
location / {
try_files $uri @proxy_to_app;
}
location @proxy_to_app {
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;
}
}
型
UPDATE我已经到达了我的代码的视图部分。因为当我像这样运行gunicorn./gunicorn_start时,我的所有13个工人都启动了,但最重要的是我得到了这个:
[2023-12-20 20:54:24 +0000] [35603] [DEBUG] GET /favicon.ico
[2023-12-20 20:54:24 +0000] [35601] [DEBUG] GET /
[2023-12-20 20:54:25 +0000] [35603] [DEBUG] Ignoring EPIPE
2023-12-20 20:54:25.372261+00:00
Hostname: vmi1520937
IP Address: 127.0.1.1
La ip 127011
[2023-12-20 20:54:31 +0000] [35596] [DEBUG] GET /
2023-12-20 20:54:32.245455+00:00
Hostname: vmi1520937
IP Address: 127.0.1.1
La ip 127011
型
这是引用index.html页面的代码的一部分,但是,我无法看到该页面。
1条答案
按热度按时间ilmyapht1#
我运行了
debug = True
和debug = True
,以查看调试代码,因为nginx日志没有给予任何错误,gunicorn运行良好。事情是这样的:虽然我已经创建了数据库,但我还没有导入表,因此服务器错误。这些表是托管的类型=在模型中为False,因为它们独立于模型创建而存在。它必须是项目代码中的某个东西,因为nginx确实在运行目录中创建了sock,而gunicorn确实 Boot 了13个工人。第一次我曾经上传一个django项目到一个裸金属vps.不是一个微不足道的斗争,以了解所有的nginx的配置,gunicorn,supervisor文件,以及他们如何相互沟通,如果你是在你自己.巨大的感谢所有那些谁尝试,我很抱歉,我给你带来了困难.