Foreword: I have written a few interfaces for deployment on the server, first select Django+uwsgi+nginx because the configuration is simple, compared to Python's simple operation features a powerful feature
Then for some versions of Django in the previous article wrote a reference: https://www.cnblogs.com/Jack-cx/p/9351633.html based on version, server PIP3 install XXX installed under
The approximate structure of my Django project:
Testwebapi
----TESTWEBAPI
----Apiso (app created)
----manage.py
1. Turn off debug
This is the deployment of the formal environment, the first to switch off the debug, refer to a previous write: Https://www.cnblogs.com/Jack-cx/p/9348326.html, set the debug, including the domain name, external network access,
In addition the database configuration itself according to the actual situation modified ~
2. Try to start,
CD/Item under
Python manage.py runserver Ip:port
There's a hole here that could be an error. No SSL library
Rpm-aq|grep OpenSSL #查看有没有包在服务器
View results-this is normal.
[Email protected] ~]# Rpm-aq|grep OpenSSL
Openssl-1.0.1e-48.el6_8.1.x86_64
Openssl-devel-1.0.1e-48.el6_8.1.x86_64
No then install
# yum Install Openssl-devel-y
# yum Install OpenSSL
Vi/usr/local/python36/modules/setup
#修改Setup文件
#修改结果如下:
# Socket Module Helper for Socket (2)
_socket socketmodule.c timemodule.c
# Socket Module helper for SSL support; You must comment out of the other
# socket line above, and possibly edit the SSL variable:
#SSL =/usr/local/ssl
_ssl _ssl.c \
-duse_ssl-i$ (SSL)/include-i$ (SSL)/INCLUDE/OPENSSL \
-l$ (SSL)/lib-lssl-lcrypto
: wq!
Re-compiling
cd/usr/local/python36/
Make && make install
Verify
>>> Import _ssl
>>> exit ()
This time in the startup project, OK ~
3. Since the boot OK, then the configuration under Uwsgi
Direct installation can
PIP3 Install Uwsgi
Creating a configuration file
Vi/etc/uwsgi.ini
[Uwsgi]
# django-related Settings
Socket =: 8100
#端口
# Django Project directory
ChDir =/opt/devpython/testwebapi
# wsgi.py, write a project name directly. Wsgi.
module = Testwebapi.wsgi
# process-related Settings
# Master
Master = True
# Number of processes
processes = 4
# ... with appropriate Permissions-may is needed
# Chmod-socket = 664
# Clear Environment on exit
Vacuum = True
Daemonize =/var/log/testwebapi.log #注意如果没有log就不在后台运行了
That's it.
Start the test,
Uwsgi--ini/etc/uwsgi.ini
View process
Ps-ef |grep Uwsgi
Root 1498 1 0 Jul21? 00:00:07 Uwsgi--ini/etc/uwsgi.ini
Root 1498 0 Jul21? 00:00:01 Uwsgi--ini/etc/uwsgi.ini
Root 1501 1498 0 Jul21? 00:00:00 Uwsgi--ini/etc/uwsgi.ini
Root 1502 1498 0 Jul21? 00:00:00 Uwsgi--ini/etc/uwsgi.ini
Root 1503 1498 0 Jul21? 00:00:00 Uwsgi--ini/etc/uwsgi.ini
Root 4992 4912 0 22:14 pts/1 00:00:00 grep--color=auto Uwsgi
It means success.
4. Last step to configure Nginx
Vi/opt/nginx/conf/nginx.conf
server {
Listen 80;
server_name www.ba.com; #配置域名, do not configure to write a localhost.
#charset Koi8-r;
#access_log Logs/host.access.log Main;
Location/{
root HTML;
Index index.html index.htm;
Include Uwsgi_params;
Uwsgi_pass Intranet IP: Port #uwsgi配置的端口号
Uwsgi_read_timeout 30;
}
Uwsgi started successfully, this will start Nginx.
./opt/nginx/sbin/nginx
View Nginx Process
Ps-ef |gerp Nginx
The following is the success ~
Root 1505 1 0 Jul21? 00:00:00 nginx:master process./opt/nginx/sbin/nginx
Nobody 1506 1505 0 Jul21? 00:00:00 Nginx:worker Process
Root 5007 4912 0 22:21 pts/1 00:00:00 grep--color=auto nginx
Specific Nginx Other operation reference: https://www.cnblogs.com/Jack-cx/p/9356467.html
Finally, the Python backend is probably over, and I'm going to start learning about performance-back to the blog park and record every pit ~ ~ ~
@ If you understand the wrong place, please leave a message to inform, thank you ~
[linux]centos7.4 Deployment Django+uwsgi+nginx