Deploy your CRM program

Publish CRM You will use the following software

  • nginx
  • uWSGI
  • CentOS7
  • CRM Project File
  • virtualenv
  • supervisor


Pthon web server development uses WSGI protocol (Web Server Gateway Interface)

The python web project generates a file by default, identifying the application module.

The production environment uses uWSGI, implements all WSGI interfaces, is written in C language, and is a highly efficient web server.

UWSGI is a full-featured HTTP server that implements WSGI protocol, uwsgi protocol, http protocol, etc.All it has to do is convert the HTTP protocol into a language-supported network protocol.For example, convert the HTTP protocol to WSGI so that Python can use it directly.


nginx is used for its reverse proxy function, and the project is deployed online through Django+uWSGI+Nginx.


1. Package project CRM folders, compress files

2. Upload files to Centos server via xftp, scp, lrzsz, etc.

Linux tips

1. Use software like xshell or iTerm to operate your linxu in multiple terminals, so that when debugging uwsgi, nginx, and project code, you can avoid switching directories back and forth to provide efficiency.

2. Note that the configuration file of the linux software has been modified, and the service must be restarted before it takes effect.


It is recommended to build a clean, isolated python interpreter environment to prevent software dependency, conflicts, etc.


Supervisor ( is a client/server service developed with Python, a process management tool under Linux/Unix system, and does not support Windows system.It can easily monitor, start, stop, and restart one or more processes.Supervisor manages processes that, when a process is accidentally killed, supervisort automatically pulls it up again when it hears that the process is dead. It is very convenient to achieve the function of automatic process recovery, and no longer needs to write a shell script to control it.

Project Deployment

Activate virtual python environment

#Create python3-based virtual interpreter environment venv
virtualenv --no-site-packages --python=python3 venv
#Activate python3 virtual environment
[root@yugo /data 11:11:30]#source venv/bin/activate
(venv) [root@yugo /data 11:11:35]#

Install uwsgi

(venv) [root@yugo /data 11:13:23]#pip3 install uwsgi

Configure the boot uwsgi.ini to start with this profile when uwsgi is started

(venv) [root@yugo /data 11:14:25]#cat uwsgi.ini
#Use when using nginx connections
#Use directly as a web server without nginx
#Absolute path to project directory
#wsgi file path, under Project wsgi-file=Ace_crm/ #Specify interpreter directory home=/data/venv processes=4 threads=2 master=True daemonize=uwsgi.log

Configure nginx

Configure nginx.conf to drop requests to django processing through the nginx reverse proxy

(venv) [root@yugo /data 11:20:32]#cat /opt/nginx1-12/conf/nginx.conf
worker_processes  1;
events {
    worker_connections  1024;
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;
    keepalive_timeout  65;
    #Define a load balancing pool, called django, in which the socket address of the uwsgi Django is written
    upstream django {
    server {
        listen       80;
        #When accessing the root path of nginx, forward the request to port 8000 of uwsgi, as written by uwsgi.ini
        location / {
        include  /opt/nginx1-12/conf/uwsgi_params;
     #Request forwarding to uwsgi program in upstream address pool uwsgi_pass django; } location /static/ { alias /opt/nginx1-12/html/static/; } } }

Hot-load nginx service, read nginx.conf content

(venv) [root@yugo /data 11:24:24]#/opt/nginx1-12/sbin/nginx -t
nginx: the configuration file /opt/nginx1-12/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx1-12/conf/nginx.conf test is successful
(venv) [root@yugo /data 11:26:07]#/opt/nginx1-12/sbin/nginx -s reload

Start uwsgi, start django

(venv) [root@yugo /data 11:26:54]#uwsgi --ini uwsgi.ini
[uWSGI] getting INI configuration from uwsgi.ini
(venv) [root@yugo /data 11:27:10]#ps -ef|grep uwsgi
root     15540     1  0 11:27 ?        00:00:00 uwsgi uwsgi.ini
root     15543 15540  0 11:27 ?        00:00:00 uwsgi uwsgi.ini
root     15544 15540  0 11:27 ?        00:00:00 uwsgi uwsgi.ini
root     15545 15540  0 11:27 ?        00:00:00 uwsgi uwsgi.ini
root     15546 15540  0 11:27 ?        00:00:00 uwsgi uwsgi.ini
root     15590 11958  0 11:27 pts/0    00:00:00 grep --color=auto uwsgi

#If you need to stop uwsgi have access to ps -ef|grep uwsgi,find pid Kill
#A better way to kill uwsgi
killall -9 uwsgi

Visit port 80 of nginx to see if the request is forwarded to django

Configure static resources for nginx

Why configure static resources?

Configuring the static resource directory is because static resources can be returned directly through nginx without requiring uwsgi, which means that uwsgi only processes the end logic, does not process static resources, and optimizes performance

Configure static resources, django and nginx

#Create a static resource store directory
[root@yugo /opt/nginx1-12/html 11:39:51]#mkdir -vp /opt/nginx1-12/html/static
mkdir: created directory '/opt/nginx1-12/html/static'
#Add permissions to directories
[root@yugo /opt/nginx1-12/html 11:40:57]#chmod  755 /opt/nginx1-12/html/static/

Configure for django

DEBUG = False

# Static files (CSS, JavaScript, Images) # STATIC_URL = '/static/' STATIC_ROOT= '/opt/nginx1-12/html/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ]

Split Line--

Collect django static files

python3 collectstatic
This statement copies all static files previously placed in static under app to the STATIC_ROOT folder set in

Requesting a static resource then goes to location/static {alias/opt/nginx1-12/html/static/} of the nginx configuration to find it

After the above steps are completed, access the server host address and port. If port 80 is configured in nginx.conf, the address bar does not need to enter a port, because the browser request port is also defaulted to port 80, and non-80 ports need to be added after ip

Keywords: Linux Nginx Django Python supervisor

Added by siwelis on Sun, 10 Nov 2019 11:40:38 +0200