This article will introduce how to deploy Django web project on Linux system. This deployment is based on the following architecture:
Linux(CentOS7)+ Python3.5 + Django1.11 + Nginx + uWSGI
The key to WSGI deployment is a callable object called application, which is used by the application server to interact with your code. It is the interface and entry for all requests.
Application is usually located in a Python module and appears in the form of an object named application, which is visible to the server.
/wsgi Py file, which contains the application object. You can use it directly. It is used by both the Django development server and the WSGI deployment of the production environment.
The WSGI server gets the path of the application object from its configuration file. Django's development server (runserver), from the configuration item WSGI_ Obtained from application. The default value is wsgi.application, pointing to /wsgi Py.
1, Install uWSGI
The main deployment platform of Django is WSGI, which is also the standard web server and application of Python.
uWSGI is a WSGI server that implements the WSGI protocol.
uWSGI is a fast, self driven, developer friendly and system administrator friendly application container server written entirely in C.
Official website address of uWSGI: https://uwsgi-docs.readthedocs.io/en/latest/index.html
According to the experience of blood and tears, please ensure that the latest version of uwsgi is installed, otherwise various pits may appear.
Therefore, it is not recommended to use: PIP3 install uwsgi (not necessarily the latest version)
Not recommended: PIP install https://projects.unbit.it/downloads/uwsgi-lts.tar.gz (not necessarily the latest version)
Instead, suggest that https://uwsgi-docs.readthedocs.io/en/latest/Download.html Page to download the source file of the Stable/LTS version.
Why the latest version? Because the current official tutorials and related technical articles are all written in the new version, many parameter names and usages have changed greatly. With the old version, you may not even be able to run.
tar -zxvf uwsgi # Enter the decompression directory python setup.py install
After installation, try running uwsgi:
root@kube mylab]# uwsgi *** Starting uWSGI 184.108.40.206 (64bit) on [Fri Jan 15 15:14:13 2021] *** compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-39) on 13 January 2021 07:53:36 os: Linux-3.10.0-1062.9.1.el7.x86_64 #1 SMP Fri Dec 6 15:49:49 UTC 2019 nodename: kube.master machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 4 current working directory: /website/mylab detected binary path: /usr/local/bin/uwsgi uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** WARNING: you are running uWSGI without its master process manager *** your processes number limit is 15065 your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** The -s/--socket option is missing and stdin is not a socket. [root@kube mylab]#
2, Configure uwsgi