Django project released deployment environment (lower)

Previous completed the installation of python, python installed next project dependencies and dependencies

1、  python-devel

Command: yum -y install python-devel

         

 

Installation Django1.8.2 pillow django-ckeditor5.4.0

pip3 install django==1.8.2

          

pip3 install pillow

          

pip3 install django-ckeditor==5.4.0

         

python uwsgi

We have already completed the deployment of python + Django environment, then we need to understand uwsgi framework of python. Next we need to understand the uwsgi python module.

Python manager.py runserver, which is a server for use in the development stage, only supports up to 200 concurrent, obviously not suitable for use in production. We in the production environment, typically used as Django apache or nginx server production server. Today we nginx as an example. But before learning deployment, we must master a program between Django and nginx, is wsgi, web server gateway interface, the English called, Web Server Gateway Interface acronym called WSGI, Python is between applications or frameworks and web servers one interface.

We deployed today use the uwsgi module, first install

pip3 install uwsgi

        

Then configure the environment variables

命令:ln /usr/local/python3/bin/uwsgi /usr/bin/uwsgi

        

Django and WSGI combination

We prepared our Django project stored in / opt / under

       [root@localhost bin]# cp -r /root/Desktop/OurBlog/ /opt/

       [root@localhost bin]#

     

Then try to start using the Django project uwsgi

Here we pay attention to before we had overlooked a file of

        

This is our project uwsgi file

        uwsgi --http 192.168.1.69:8000 --file OurBlog/wsgi.py --static-map=/static=static

        

 

当然,这里我们要配置seLinux,防火墙和Django的settings        

关闭selinux

命令: setenforce 0

关闭防火墙

命令:systemctl stop firewalld.service

Settings配置

ED_HOSTS = ["*"] 允许所有访问

然后发起访问

        成功界面《:8000》

 

django+nginx+uwsgi

上面我们用命令启动了uwsgi,但是体验不太好,所以我们在这里使用ini文件启动uwsgi服务器

在项目同等级目录下创建script目录

         

 

然后在当中编写uwsgi.ini文件,内容如下

[uwsgi]

chdir=/opt/OurBlog   #项目目录

module=OurBlog.wsgi:application  #指定项目的application

socket=/opt/script/uwsgi.sock  #指定sock的文件路径

workers=5  #进程个数

pidfile=/opt/script/uwsgi.pid

http=192.168.2.69:8000  #指定IP端口

static-map=/static=/opt/OurBlog/static  #指定静态文件

uid=root  #用户

gid=root  #组

master=true  #启用主进程

vacuum=true  #自动移除unix Socket和pid文件当服务停止的时候

enable-threads=true #启用线程

thunder-lock=true #序列化接受的内容,如果可能的话

harakiri=30 #设置自中断时间

post-buffering=4096 #设置缓冲

daemonize=/opt/script/uwsgi.log #设置日志目录

然后启动uwsgi服务

Uwsgi --ini uwsgi.ini(脚本名称)

       

 

然后可以正常访问

       成功界面《:8000》

安装nginx服务器

我们直接安装nginx是没有的,所以,需要我们wget

命令:wget -c https://nginx.org/download/nginx-1.12.2.tar.gz

       

解压

命令:tar -zxvf nginx-1.12.2.tar.gz && cd nginx-1.12.2

        

自定义配置

命令:./configure \

       

编译安装

命令:make && make install

        

       

然后配置环境变量

命令:ln sbin/nginx /usr/bin/nginx

       

启动nginx查看效果

       

       

进行nginx配置,(配置nginx.conf,配置之前进行备份)

备份

        

然后开始配置

配置节选1

http {

    include       mime.types;

    default_type  application/octet-stream;

    #这里规定了日志的格式,默认是注释的,我们需要解开注释

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    #access_log  logs/access.log  main;

 

    sendfile        on;

    #tcp_nopush     on;

 

    #keepalive_timeout  0;

    keepalive_timeout  65;

 

    #gzip  on;

 

    server {

      

 

配置节选2

    server {

        listen       80;  #监听端口

        server_name  OurBlog; #服务名称

 

        charset utf-8; #服务器编码

 

        access_log  /var/log/nginx/access.log  main; #访问日志路径,注意:这个目录可能没有,需要创建

 

        gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream; #压缩格式

 

        error_log /var/log/nginx/error.log error; #错误日志注意:这个目录可能没有,需要创建

        location / {

            include uwsgi_params; #nginx加载uwsgi模块

            uwsgi_connect_timeout 30; #连键超时时间

            uwsgi_pass unix:/opt/script/uwsgi.sock; #nginx对应的uwsgi socket文件

        }

 

        location = /static/ {

            alias /opt/OurBlog/static;  #静态文件路径

            index index.html index.htm;  #首页

        }

    }

     

效果如下:

      <自己事实吧  结果就不用展示了吧! 实属不易 牺牲了大美的娱乐时光 谢谢大家>

Guess you like

Origin www.cnblogs.com/xiaolizikj/p/11373486.html