I am not able to access server when starting gunicorn via a .bash file I made. 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. 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 project.wsgi:application --bind 192.168.1.130:8000
Above you use --bind
with host:port
but below:
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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.