在CentOS7上用nginx+uwsgi部署一个Django项目

安装依赖环境
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
下载Python3
 wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
安装python3

安装在/usr/local/python3.创建目录:

mkdir -p /usr/local/python3

解压下载好的Python3

tar -zxvf Python-3.6.1.tgz
进入解压后的目录,编译安装。
cd Python-3.6.1
./configure --prefix=/usr/local/python3

如查不成功需要:

yum install gcc-c++

然后再执行./configure.

make
make install
建立python3的软链
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
并将/usr/local/python3/bin加入PATH
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH

按ESC,输入:wq回车退出。

修改完记得执行行下面的命令,让上一步的修改生效:

source ~/.bash_profile

检查Python3及pip3是否正常可用:

python3 -V
pip3 -V

升级pip3

python -m pip install --upgrade pip setuptools
安装mariadb
yum install mariadb-server -y
systemctl start mariadb
创建数据库的可操作用户
mysql
MariaDB [(none)]> grant all on *.* to root@'developerIp' identified by '123456';
用uwsig开启服务

方式一:

uwsgi --http 0.0.0.0:8080 --file bbs/wsgi.py --static-map=/static=/project/bbs/static

方式二:
创建一个uwsgi.ini文件

touch uwsgi.ini
vim uwsgi.ini
# uwsig使用配置文件启动
[uwsgi]
# 项目目录
chdir=/project/bbs/
# 指定项目的application
module=bbs.wsgi:application
# 指定sock的文件路径       
socket=/project/bbs/uwsgi.sock
# 进程个数       
workers=5
pidfile=/project/bbs/uwsgi.pid
# 指定IP端口       
http=0.0.0.0:8080
# 指定静态文件
static-map=/static=/project/bbs/static
# 启动uwsgi的用户名和用户组
uid=root
gid=root
# 启用主进程
master=true
# 自动移除unix Socket和pid文件当服务停止的时候
vacuum=true
# 序列化接受的内容,如果可能的话
thunder-lock=true
# 启用线程
enable-threads=true
# 设置自中断时间
harakiri=30
# 设置缓冲
post-buffering=4096
# 设置日志目录
daemonize=/project/bbs/uwsgi.log
uwsgi --ini /project/bbs/uwsgi.ini

查看进程

ps -ef|grep 'uwsgi'
压力测试
 ab -n 100000 -c 100 http://111.231.58.148/index/
使用ngix服务器
yum install nginx -y
 mv /etc/nginx/nginx.conf /temp
 cd /etc/nginx/
 touch nginx.conf
 vim nginx.conf

编缉nginx.conf

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server { 
        listen 80;
        server_name localhost;
        charset utf-8;

        location / { 
           include uwsgi_params;
           uwsgi_connect_timeout 30;
           uwsgi_pass unix:/project/bbs/uwsgi.sock;
        }
        location /static/ {
           alias /project/bbs/static/;
           index index.html index.htm;
        }
    }
}

启动ngnix

systemctl start nginx
ps -ef #查看进程
netstat  -lntup#查看端口
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值