uwsgi + nginx 搭建

uwsgi + nginx 搭建
  1. 安装nginx
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-centos-7
  1. 安装virtualenvwrapper
yum install python-setuptools python-devel
pip install virtualenvwrapper
编辑.bashrc文件
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source /usr/local/bin/virtualenvwrapper.sh
重新加载.bashrc文件
source  ~/.bashrc

新建虚拟环境
mkvirtualenv mxoline

进入虚拟环境 
workon mxoline

安装pip包
pip install -r requirements.txt
  1. 安装uwsgi

    pip install uwsgi

  2. 测试uwsgi

    uwsgi –http :8000 –module Mxoline.wsgi

  3. 配置nginx

    新建uc_nginx.conf

# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 127.0.0.1:8000; # for a web port socket (we'll use this first)
}
# configuration of the server

server {
# the port your site will be served on
listen      80;
# the domain name it will serve for
server_name 你的ip地址 ; # substitute your machine's IP address or FQDN
charset     utf-8;

# max upload size
client_max_body_size 75M;   # adjust to taste

# Django media
location /media  {
    alias 你的目录/Mxonline/media;  # 指向django的media目录
}

location /static {
    alias 你的目录/Mxonline/static; # 指向django的static目录
}

# Finally, send all non-media requests to the Django server.
location / {
    uwsgi_pass  django;
    include     uwsgi_params; # the uwsgi_params file you installed
}
}
  1. 将该配置文件加入到nginx的启动配置文件中

    sudo ln -s 你的目录/Mxonline/conf/nginx/uc_nginx.conf /etc/nginx/conf.d/

  2. 拉取所有需要的static file 到同一个目录

    在django的setting文件中,添加下面一行内容:

    STATIC_ROOT = os.path.join(BASE_DIR, "static/")
    

    运行命令

    python manage.py collectstatic
    
  3. 运行nginx

    sudo /usr/sbin/nginx

  4. 运行nginx

workon mxonline
uwsgi -i 你的目录/Mxonline/conf/uwsgi &

10 访问

http://你的ip地址/

最后欢迎大家观看我关于 django + xadmin的教程:

http://coding.imooc.com/class/evaluation/78.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值