zoukankan      html  css  js  c++  java
  • CentOS上部署Django+Nginx+Uwsgi环境

    在CentOS上部署Django+Nginx+Uwsgi环境

     奇谭  2016-09-01  评论
     

    VirtualEnv的作用:创建隔离的Python环境,解决模块或库的版本冲突或依赖。
    安装virtualenv见CentOS上搭建virtualenv虚拟环境

    在这里我们以实际部署一个项目为例,看看django+nginx+uwsgi的环境是怎么部署的

    首先通过virtualenv创建python虚拟环境

    $ virtualenv imaojia
    

    然后激活虚拟环境并安装django

    $ pip install django -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
    

    virtualenv

    接着新建一个项目并通过runserver方式启动测试

    $ cd /data/wwwroot/
    $ django-admin startproject imaojia
    

    ![/media/pictures/2016/09/01/django-app.png)

    $ cd imaojia/
    $ python manage.py runserver 0.0.0.0:8082
    

    start-app

    打开我们的浏览器,看到如下内容表明我们的项目已经正常跑起来了

    web

    ok,现在开始编写uwsgi配置

    $ cat > uwsgi.ini <<EOF
    [uwsgi]
    home=/home/qitanl/imaojia
    chdir=/data/wwwroot/imaojia
    module=imaojia.wsgi:application 
    master=True 
    pidfile=/data/wwwroot/imaojia/imaojia.pid 
    vacuum=True 
    max-requests=1000 
    daemonize=/data/wwwroot/imaojia/uwsgi.log
    socket = 0.0.0.0:10000
    #http = 0.0.0.0:10000
    EOF
    

    接着安装uwsgi并运行

    ## 通过pip安装uwsgi,已安装的可以忽略
    $ pip install uwsgi -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
    $ uwsgi --ini uwsgi
    

    uwsgi

    ok,现在安装nginx并编写nginx配置文件

    ## 通过yum快速安装nginx,已安装的忽略
    $ yum -y install nginx
    $ cat > /etc/nginx/conf.d/imaojia.conf <<EOF
    server
            {
            listen 8082;
            server_name soms.imaojia.com;
    
            access_log  /data/wwwroot/imaojia/imaojia.access.log main;
    
            location / {
                root /data/wwwroot/imaojia;
    
            ## uwsgi配置的端口
                uwsgi_pass 127.0.0.1:10000;
                include uwsgi_params;
                uwsgi_param UWSGI_CHDIR  /data/wwwroot/imaojia;
                uwsgi_param UWSGI_SCRIPT wsgi;
            }
            location ~ .*.(log|php|pl|py|sh|cgi)$ {
                    return 403;
            }
            location /static/ {
                    root /data/wwwroot/imaojia;
            access_log off;
            }
            location ~ .*.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
                    root /data/wwwroot/imaojia;
                    expires 30d;
            }
            location ~ .*.(js|css)?(.*)
            {
                    root /data/wwwroot/imaojia;
                    expires      12h;
            }
        }
    EOF
    

    嗯,现在启动nginx并访问看看

    $ sudo systemctl start nginx
    $ curl http://soms.imaojia.com:8082/
    

    web-curl

     
  • 相关阅读:
    JDBC连接
    Ubuntu 16.04安装MySQL(5.7.18)
    AOP拦截日志报错llegalStateException: It is illegal to call this method if the current request is not in asynchronous mode
    mybatis笔记
    打扮IDEA更换主题
    简单的IDEA破解到2099年
    UML之时序图详解
    UML之类图详解
    UML之用例图详解
    spring和springboot常用注解总结
  • 原文地址:https://www.cnblogs.com/xuaijun/p/7860392.html
Copyright © 2011-2022 走看看