简体   繁体   English

通过.bash文件调用Gunicorn时无法访问服务器

[英]Not able to access server when invoking gunicorn via .bash file

I am not able to access server when starting gunicorn via a .bash file I made. 通过我制作的.bash文件启动gunicorn时,我无法访问服务器。 It works when I do it manually with this command 当我使用此命令手动执行时,它可以工作

$ gunicorn project.wsgi:application --bind 192.168.1.130:8000

Created a gunicorn.bash file from tutorials. 通过教程创建了gunicorn.bash文件。 I looks like this and runs without fault. 我看起来像这样,运行正常。

#!/bin/bash

NAME="project"                                                   # Name of the application
DJANGODIR=/home/username/projects/project                    # Django project directory
SOCKFILE=/home/username/.venvs/project/run/gunicorn.sock     # We will communicate using this unix socket
USER=username                                              # the user to run as
GROUP=username                                             # the group to run as
NUM_WORKERS=1                                                   # how many worker processes shoul Gunicorn spawn
DJANGO_SETTINGS_MODULE=project.settings.production               # which settings file should Django use
DJANGO_WSGI_MODULE=project.wsgi                                  # WSGI module name
echo "Starting $NAME as `whoami`"

# Activate the virtual environment

cd $DJANGODIR
source /home/username/.venvs/project/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exsist

RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start yout 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 \
  --log-level=debug \
  --log-file=-

I don't know how to troubleshoot this? 我不知道该如何解决? Maybe some command to see what differs in running settings from manually starting gunicorn and from the .bash file? 也许有些命令可以查看运行设置与手动启动gunicorn和.bash文件有何不同?

$ gunicorn project.wsgi:application --bind 192.168.1.130:8000

Above you use --bind with host:port but below: 上面使用--bindhost:port --bind ,但下面使用:

exec gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --bind=unix:$SOCKFILE \
  --log-level=debug \
  --log-file=-

you specify unix:file which will make your gunicorn listen on unix socket file instead of on your network interface:port, so just replace the unix:$SOCKFILE with 192.168.1.130:8000 and it should be accessible as expected 您指定unix:file ,它将使您的gunicorn在unix套接字文件上而不是在网络接口:port上侦听,因此只需将unix:$SOCKFILE替换为192.168.1.130:8000 ,它应该可以按预期访问

Additionally you can try and connect to the current config with a curl ( curl --unix-socket /path/to/socket http:/some/resurce ) or other tool of your choice to verify that it actually runs 另外,您可以尝试使用curlcurl --unix-socket /path/to/socket http:/some/resurce )或您选择的其他工具连接到当前配置,以验证其是否实际运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM