简体   繁体   中英

Missing module when deploying Django on AWS Ubuntu EC2

I'm having some problems hosting a Django site on an ubuntu AWS server. I have it all running on local host fine.

I am following these instructions: https://github.com/ialbert/biostar-central/blob/master/docs/deploy.md

when i try and run it in aws console using:

waitress-serve --port 8080 live.deploy.simple_wsgi:application

i get import error:

 1. No module named simple_wsgi

Then if i use the base settings file (not the cut down one), i get import error

 1. No module named logger

I've tried moving settings files around and copying the settings files to deploy.env and deploy.py and then sample.env and sample.py and i can't get it running. Please help

I had the same issue and opened it in Biostar project .

Here is how I fixed it: by serving the application via gunicorn and nginx .

Here is my script:

cp live/staging.env live/deploy.env
cp live/staging.py live/deploy.py
# Replace the value of DJANGO_SETTINGS_MODULE to "live.deploy" thanks to http://stackoverflow.com/a/5955623/535203
sed -i -e '/DJANGO_SETTINGS_MODULE=/ s/=.*/=live.deploy/' live/deploy.env
[[ -n "$BIOSTAR_HOSTNAME" ]] && sed -i -e "/BIOSTAR_HOSTNAME=/ s/=.*/=$BIOSTAR_HOSTNAME/" live/deploy.env
source live/deploy.env
biostar.sh init import
# Nginx config based on http://docs.gunicorn.org/en/stable/deploy.html and https://github.com/ialbert/biostar-central/blob/production/conf/server/biostar.nginx.conf
tee "$LIVE_DIR/nginx.conf" <<EOF
worker_processes 1;

user nobody nogroup;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;

events {
  worker_connections 1024; # increase if you have lots of clients
  accept_mutex off; # set to 'on' if nginx worker_processes > 1
  # 'use epoll;' to enable for Linux 2.6+
  # 'use kqueue;' to enable for FreeBSD, OSX
}

http {
  include /etc/nginx/mime.types;
  # fallback in case we can't determine a type
  default_type application/octet-stream;
  access_log /tmp/nginx.access.log combined;
  sendfile on;

  upstream app_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response

    # for UNIX domain socket setups
    server unix:/tmp/biostar.sock fail_timeout=0;

    # for a TCP configuration
    # server 192.168.0.7:8000 fail_timeout=0;
  }

  server {
    # if no Host match, close the connection to prevent host spoofing
    listen 8080 default_server;
    return 444;
  }

  server {
    # use 'listen 80 deferred;' for Linux
    # use 'listen 80 accept_filter=httpready;' for FreeBSD
    listen 8080;
    client_max_body_size 5M;

    # set the correct host(s) for your site
    server_name $SITE_DOMAIN;

    keepalive_timeout 25s;

    # path for static files
    root $LIVE_DIR/export/;
    location = /favicon.ico {
        alias    $LIVE_DIR/export/static/favicon.ico;
    }

    location = /sitemap.xml {
        alias    $LIVE_DIR/export/static/sitemap.xml;
    }

    location = /robots.txt {
        alias    $LIVE_DIR/export/static/robots.txt;
    }

    location /static/ {
        autoindex on;
        expires max;
        add_header Pragma public;
        add_header Cache-Control "public";
        access_log off;
    }

    location / {
      # checks for static file, if not found proxy to app
      try_files \$uri @proxy_to_app;
    }

    location @proxy_to_app {
      proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
      # enable this if and only if you use HTTPS
      # proxy_set_header X-Forwarded-Proto https;
      proxy_set_header Host \$http_host;
      # we don't want nginx trying to do something clever with
      # redirects, we set the Host: header above already.
      proxy_redirect off;
      proxy_pass http://app_server;
    }
  }
}
EOF

gunicorn -b unix:/tmp/biostar.sock biostar.wsgi &
# Start Nginx in non daemon mode thanks to http://stackoverflow.com/a/28099946/535203
nginx -g 'daemon off;' -c "$LIVE_DIR/nginx.conf"

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.

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