Nginx配置
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
include /etc/nginx/uwsgi_params;
uwsgi_pass 127.0.0.1:8090;
}
uwsgi配置
在Django的项目目录下创建一个uwsgi.ini并写入如下内容
[uwsgi]
socket= 127.0.0.1:8090
#http= 127.0.0.1:8090
chdir=/xzpj/myweb
processes=4
threads=2
master=True
module = myweb.wsgi:application
vacuum = True
启动uwsgi
uwsgi --ini /xxx/xxxx/uwsgi.ini (表示项目路径下的uwsgi.ini)
启动Nginx
项目遇到的问题
再次用启动virtualenvwrapper时报错
/usr/bin/python: No module named virtualenvwrapper
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH is
set properly.
原因:Ubuntu安装了2.7和3.x两个版本的python,而我使用的3.6的用pip3安装,2.7找不到virtualenvwrapper模块
virtualenvwrapper.sh内路径代码如下:
if [ "$VIRTUALENVWRAPPER_PYTHON" = "" ] then
VIRTUALENVWRAPPER_PYTHON="$(command \which python)"
fi
因此需要增加环境变量
VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
关于virtualenvwrapper使用技巧
配置.bashrc文件
在.bashrc添加如下代码:
export WORKON_HOME=~/Envs(你的虚拟环境路径)
source /usr/local/bin/virtualenvwrapper.sh
这样系统会自动加载你的虚拟环境,不用手动运行virtualenvwrapper.sh脚本
领取专属 10元无门槛券
私享最新 技术干货