在AWS Ubuntu EC2上部署Django时缺少模块

时间:2016-08-26 10:46:20

标签: python django amazon-web-services nginx wsgi

我在ubuntu AWS服务器上托管Django网站时遇到了一些问题。我把它全部运行在本地主机上。

我正在遵循这些说明:https://github.com/ialbert/biostar-central/blob/master/docs/deploy.md

当我尝试使用以下命令在aws控制台中运行它时:

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

我收到导入错误:

 1. No module named simple_wsgi

然后,如果我使用基本设置文件(而不是减少的文件),我会得到导入错误

 1. No module named logger

我尝试移动设置文件并将设置文件复制到deploy.env和deploy.py,然后是sample.env和sample.py,我无法运行它。请帮忙

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题和opened it in Biostar project

以下是我修复它的方法:通过gunicornnginx提供应用程序。

这是我的剧本:

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"