在 AWS Ubuntu EC2 上部署 Django 时缺少模块
Posted
技术标签:
【中文标题】在 AWS Ubuntu EC2 上部署 Django 时缺少模块【英文标题】:Missing module when deploying Django on AWS Ubuntu EC2 【发布时间】:2017-01-03 00:25:23 【问题描述】:我在 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,但我无法让它运行。请帮忙
【问题讨论】:
在第一种情况下它是一个缺失的依赖项。使用“pip install simple_wsgi”或在配置文件中提及 simple_wsgi。 【参考方案1】:我遇到了同样的问题,opened it in Biostar project。
这是我修复它的方法:通过gunicorn
和nginx
为应用程序提供服务。
这是我的脚本:
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://***.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://***.com/a/28099946/535203
nginx -g 'daemon off;' -c "$LIVE_DIR/nginx.conf"
【讨论】:
以上是关于在 AWS Ubuntu EC2 上部署 Django 时缺少模块的主要内容,如果未能解决你的问题,请参考以下文章
如何在运行 Ubuntu 的 AWS EC2 上配置多个虚拟主机? [关闭]
无法在 AWS EC2 (Ubuntu) apache 系统上 SSL Godaddy 验证证书
AWS ec2 根卷增加:在 aws ubuntu 实例上扩展弹性根卷不起作用
从 Eclipse 在 AWS EC2 上部署 Java webapp