美文网首页
Centos7 nginx+uwsgi+mysql Django

Centos7 nginx+uwsgi+mysql Django

作者: 品聚微盟 | 来源:发表于2018-03-22 14:51 被阅读0次

    1、安装mysql,采用docker

    2、安装uwsgi

      Pip3 install uwsgi

    3、测试uwsgi是否安装成功

    (1)/hom/www目录新建test.py

         def application(env, start_response):

             start_response('200 OK', [('Content-Type','text/html')])

             return [b"Hello World"]

    * python3版本 必须是 return [b"Hello World"]

    (2)运行uwsgi --http :8001 --wsgi-file /home/www/test.py

    (3) 打开浏览器IP:8001,出现下图表示uwsgi搭建成功

    4、用uwsgi搭建django项目

    (1)在/home目录建立wwwroot 目录用于存在项目

    (2)将项目MtcProject放入wwwroot,并修改mysql信息

    (3)将/home/wwwroot/MtcProject目录建立uwsgi.ini

    [uwsgi]

    Socket=192.168.1.185:9090

    chdir=/home/wwwroot/MtcProject

    module=MtcProject.wsgi

    master = true         

    processes=2

    threads=2

    max-requests=2000

    chmod-socket=664

    vacuum=true

    daemonize = /home/wwwroot/MtcProject/uwsgi.log

    说明:

    chdir指自己工程的绝对路径; module指的是wsgi.py在自己工程中的相对路径,”.”指代一层目录;我的django工程的wsgi.py文件是在”/home/wwwroot/MtcProject/wsgi.py”,所以写成MtcProject.wsgi; daemonize指定uWSGI日志的存储路径。

    5、启动uwsgi

       uwsgi --ini /wwwroot/destiny/destiny.ini

    6、[endif]打开浏览器访问:192.168.1.185:9090(ps:打开后样式会有问题,需要nginx去处理static,见第7步)

    问题:1、

    解决方案:打开项目中的setting.py,修改

    2、服务器重置,无法访问

    7、安装nginx

    (1) 安装依赖

    yum -y install gcc gcc-c++ autoconf automake make

    yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel

    (2) 安装nginx

    //下载软件

    wget http://nginx.org/download/nginx-1.13.7.tar.gz

    //解压

    tar zxvf nginx-1.13.7.tar.gz

    //创建安装目录

    mkdir -p /usr/local/nginx

    //修改配置

    cd nginx-1.13.7/

    ./configure --prefix=/usr/local/nginx  

    //安装

    make && make install

    (3) 启动

           进入安装目录

    cd /usr/local/nginx/sbin

    启动

    ./nginx    

    (4)关闭防火墙或者开放端口(远程访问才会需要)

    关闭防火墙:

    CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。

    systemctl stop firewalld.service #停止firewall

    systemctl disable firewalld.service #禁止firewall开机启动

    firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

    开放端口:

    添加firewall-cmd --zone=public --add-port=80/tcp --permanent    (--permanent永久生效,没有此参数重启后失效)

    重新载入firewall-cmd --reload

    查看firewall-cmd --zone= public --query-port=80/tcp

    删除firewall-cmd --zone= public --remove-port=80/tcp --permane

    相关文章

      网友评论

          本文标题:Centos7 nginx+uwsgi+mysql Django

          本文链接:https://www.haomeiwen.com/subject/jdyaqftx.html