[Django]-Django-nginx-gunicorn – not working

0👍

Try /etc/gunicorn.d instead of your own sh file

0👍

I Configure Django App with Gunicorn and Nginx on EC2

nano /etc/init/site1.conf

description "site1 web server"
start on runlevel [2345]
stop on runlevel [06]
respawn
respawn limit 10 5
exec /home/scripts/gunicorn_runserver.sh

and in gunicorn_runserver.sh

#!/bin/bash
  set -e
  LOGFILE=/var/log/nginx/site1.log
  NUM_WORKERS=10
  # user/group to run as
  USER=www-data
  GROUP=adm
  cd /home/projects/project_name/
  #  source ../../bin/activate
  exec gunicorn_django -w $NUM_WORKERS \
    --user=$USER --group=$GROUP --log-level=error \
    --log-file=$LOGFILE 2>>$LOGFILE

Nginx conf

upstream app_server_hana {
server localhost:8000 fail_timeout=0;
}

location  / {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header Host $http_host;
  proxy_redirect off;

  if (!-f $request_filename) {
          proxy_pass http://app_server_site1;
          break;
  }
}

Finally

/etc/init.d/nginx restart
service site1 start
👤Rakesh

Leave a comment