Centos部署 django 服务 nginx uwsgi

栏目: Python · 发布时间: 7年前

内容简介:这是通过编译的方式来安装的输入 python3 –version 和 pip3 –version 进行测试通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页​面进行测试

1.安装 python 3

yum -y install wget gcc make  zlib-devel readline-devel  bzip2-devel ncurses-devel sqlite-devel gdbm-devel xz-devel tk-devel openssl-devel
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
xz -d Python-3.6.1.tar.xz
tar -xvf Python-3.6.1.tar
cd Python-3.6.1
./configure --prefix=/usr/local/python3.6 --enable-optimizations
make
make install
ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
 ln -s /usr/local/python3.6/bin/pip3 /usr/bin/pip3

这是通过编译的方式来安装的

输入 python3 –version 和 pip3 –version 进行测试

2. 安装nginx

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
sudo yum install -y nginx
sudo systemctl start nginx.service

通过你的域名或IP来访问你的Web页面来预览一下Nginx的默认页​面进行测试

3.下载代码,上传到服务器的/var/www 目录

4. 安装依赖

pip3 install django
pip3 install uwsgi
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi3

5. 独立运行进行测试

cd /var/www/dexundjango
python3 manage.py runserver 0.0.0.0:8014

测试通过后,Ctrl + C 停止运行

6.uwsgi

sudo mkdir -p /etc/uwsgi/sites
sudo mkdir -p /var/log/uwsgi
cd /etc/uwsgi/sites
sudo vi /etc/uwsgi/sites/mysite.ini
[uwsgi]
socket = 127.0.0.1:10000
chdir=/var/www/dexundjango
module=mysite.wsgi:application
master=True
pidfile=/tmp/project-master.pid
vacuum=True
max-requests=5000
daemonize=/var/log/uwsgi/mysite.log

7. nginx 配置

vi /usr/local/nginx/conf/nginx.conf  (根据本地的配置路径)
find / -name uwsgi_params 来替换下面的uwsgi_params路径
server {
    listen 8014; #暴露给外部访问的端口
    server_name localhost;
        charset utf-8;
    location / {
        include /usr/local/nginx/conf/uwsgi_params;
        uwsgi_pass 127.0.0.1:10000;  # 必须和uwsgi.ini配置的端口一致
    }
    location /static/ {
        alias /home/www/dexundjango/trade/static/; #项目静态路径设置
    }

8. 启动uwsgi

uwsgi3 --ini /etc/uwsgi/sites/mysite.ini

9. 开机启动uwsgi

vi /etc/init.d/uwsgi
#!/bin/bash
# chkconfig: - 85 15
uwsgi=/usr/bin/uwsgi3
api_conf=/etc/uwsgi/sites/mysite.ini

case $1 in
    start)
        echo -n "Starting uWsgi"
        nohup $uwsgi -i $api_conf >/var/log/uwsgi/project-api.log 2>&1 &
        echo " done"
    ;;

    stop)
        echo -n "Stopping uWsgi"
        killall -9 uwsgi
        echo " done"
    ;;

    restart)
        $0 stop
        $0 start
    ;;

    show)
        ps -ef|grep uwsgi
    ;;

    *)
        echo -n "Usage: $0 {start|restart|stop|show}"
    ;;

esac
chmod +x /etc/init.d/uwsgi
chkconfig --add uwsgi
chkconfig uwsgi on

5235


以上所述就是小编给大家介绍的《Centos部署 django 服务 nginx uwsgi》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

C++ How to Program (5th Edition) (How to Program)

C++ How to Program (5th Edition) (How to Program)

Harvey & Paul) Deitel & Associates / Prentice Hall / 2005-01-05 / USD 98.00

With over 250,000 sold, Harvey and Paul Deitel's C++ How to Program is the world's best-selling introduction to C++ programming. Now, this classic has been thoroughly updated! The Deitels' groundbreak......一起来看看 《C++ How to Program (5th Edition) (How to Program)》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具