Setting up django with nginx on EC2

前端 未结 1 1070
时光取名叫无心
时光取名叫无心 2021-01-03 09:30

I\'m trying to run my django app with nginx, but when trying to connect to my EC2 IP im getting \"connection timed out\" error. It properly shows django \"deafult\" page on

相关标签:
1条回答
  • 2021-01-03 10:23

    I created my Django site on EC2 using Nginx and Gunicorn and These are the steps i followed

    easy_install gunicorn
    apt-get install nginx
    

    nano /etc/init/site1.conf and added

    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
    

    and in Nginx conf

    upstream app_server_site1 {
        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
    

    Detail description about Nginx+Django+Gunicorn here and Nginx+Django+Fcgi here

    0 讨论(0)
提交回复
热议问题