Release CRM you will use the following software
- Nginx
- Uwsgi
- Centos7
- CRM Project File
- Virtualenv
- Supervisor
Wsgi, uwsgi
Python web server development uses the wsgi protocol (Web Server Gateway Interface)
By default, the Python web project generates a wsgi. py file to determine the application module.
In the production environment, uwsgi is used to implement all wsgi interfaces. It is a highly efficient Web Server written in C language.
Uwsgi is a full-featured HTTP server that implements the wsgi, uwsgi, and HTTP protocols. What it needs to do is to convert the HTTP protocol to the network protocol supported by the language. For example, you can convert HTTP to wsgi so that python can use it directly.
Nginx
Nginx is used for its reverse proxy function. The project will deploy the server online through Django + uwsgi + nginx.
Centos
1. Package the CRM folder of the project and compress the file
2. upload files to the centos server through xftp, SCP, lrzsz, etc.
Linux tips
1. Use xshell, iterm, and other software to operate your linxu on multiple terminals. In this way, when debugging uwsgi, nginx, and project code, you can avoid switching directories back and forth to provide work efficiency.
2. Note that the configuration file of the Linux software must be restarted to take effect.
Virtualenv
We recommend that you build a clean and isolated Python interpreter environment to prevent software dependencies and conflicts.
Supervisor
Supervisor (http://supervisord.org/) is a Client/Server Service developed with python, is a process management tool under Linux/Unix systems, does not support windows. It can easily monitor, start, stop, and restart one or more processes. When a process managed by a supervisor is accidentally killed, supervisort automatically pulls the process again after listening to it, making it easy to automatically restore the process, you no longer need to write shell scripts for control.
Project deployment activates the virtual Python Environment
# Create a virtual interpreter Environment named venvvirtualenv -- no-site-packages -- Python = python3 venv # activate the python3 Virtual Environment [[email protected]/Data 11:11:30] # source venv/bin /activate (venv) [[email protected]/Data 11:11:35] #
Install uwsgi
(venv) [[email protected] /data 11:13:23]#pip3 install uwsgi
Configure uwsgi. ini to start uwsgi with this configuration file.
(Venv) [[email protected]/Data 11:14:25] # Cat uwsgi. INI [uwsgi] # Use SOCKET = 0.0.0.0: 8000 when using nginx connection # Use nginx directly as a web server # HTTP = 0.0.0.0: 9000 # project directory absolute path chdir =/data/ace_crm
# Wsgi file path, under the project wsgi-file = ace_crm/wsgi. PY # specify the interpreter directory home =/data/venvprocesses = 4 threads = 2 master = truepidfile = uwsgi. piddaemonize = uwsgi. log
Configure nginx
Configure nginx. conf and use nginx reverse proxy to throw the request to Django for processing.
(Venv) [[email protected]/Data 11:20:32] # Cat/opt/nginx1-12/CONF/nginx. confworker_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 $ response" $ http_referer "'' "$ http_user_agent" "$ http_x_forwarded_for "'; access_log logs/access. log main; sendfile on; keepalive_timeout 65; # defines the Server Load balancer pool, which is called Django. The socket address upstream Django {server 0.0.0.0: 8000;} is written into the pool and published by uwsgi ;} server {Listen 80; SERVER_NAME pythonav.cn; # when accessing the nginx root path, forward the request to port 8000 of uwsgi. INI write consistent location/{include/opt/nginx1-12/CONF/uwsgi_params;
# Uwsgi program uwsgi_pass Django;} location/static/{alias/opt/nginx1-12/html/static /;}}}
Load the nginx service and read the nginx. conf content.
(venv) [[email protected] /data 11:24:24]#/opt/nginx1-12/sbin/nginx -tnginx: the configuration file /opt/nginx1-12/conf/nginx.conf syntax is oknginx: configuration file /opt/nginx1-12/conf/nginx.conf test is successful(venv) [[email protected] /data 11:26:07]#/opt/nginx1-12/sbin/nginx -s reload
Start uwsgi and Django
(Venv) [[email protected]/Data 11:26:54] # uwsgi -- ini uwsgi. INI [uwsgi] Getting ini configuration from uwsgi. INI (venv) [[email protected]/Data 11:27:10] # ps-Ef | grep uwsgiroot 15540 1 0? 00:00:00 uwsgi. iniroot 15543 15540 0? 00:00:00 uwsgi. iniroot 15544 15540 0? 00:00:00 uwsgi. iniroot 15545 15540 0? 00:00:00 uwsgi. iniroot 15546 15540 0? 00:00:00 uwsgi. iniroot 15590 11958 0 00:00:00 pts/0 grep -- color = auto uwsgi
# If you need to stop uwsgi, you can use PS-Ef | grep uwsgi and find the PID to kill
# A better way to kill uwsgi
Killall-9 uwsgi
Access Port 80 of nginx and check whether the request is forwarded to Django.
Http://pythonav.cn/login/42410.0.0.10/login
Configure nginx static Resources
Why do I need to configure static resources?
The static resource directory is configured because the static resources can be directly returned through nginx, and uwsgi is not required. That is, uwsgi only processes backend logic, does not process static resources, and optimizes performance.
Configure static resources, Django and nginx
# Create a static resource storage directory [[email protected]/opt/nginx1-12/html 11:39:51] # mkdir-VP/opt/nginx1-12/html/staticmkdir: created directory '/opt/nginx1-12/html/static'
# Add permissions to directories
[[Email protected]/opt/nginx1-12/html 11:40:57] # chmod 755/opt/nginx1-12/html/static/
Configure settings. py of Django
DEBUG = FalseALLOWED_HOSTS = [‘*‘]
# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/1.11/howto/static-files/STATIC_URL = ‘/static/‘STATIC_ROOT= ‘/opt/nginx1-12/html/static/‘STATICFILES_DIRS = [ os.path.join(BASE_DIR, ‘static‘)]
Split line --
After completing the preceding steps, access the server host address and port if nginx. if port 80 is configured in Conf, you do not need to enter the port in the address bar, because the browser request port is also the default port 80. If the port is not port 80, you must add it after the IP address.
Finished. If you have any questions, try again.
Old boy Education
QQ: 877348180
Teach you how to publish CRM