Centos+flask+uwsgi+nginx+supervisor Deployment Summary

Source: Internet
Author: User
Tags virtual environment
0x00 Head

Used to like using Ubuntu, but the actual deployment of the project laboratory is still required to use CentOS, had to put it again, midway encountered a lot of pits, make a note for later inquiries, do not want to go over the pile of bookmarks, a mess, or their summary of things look comfortable. 0x01 Mount Pip and Easy_install

Install Easy_install

Wget-q http://peak.telecommunity.com/dist/ez_setup.py
python ez_setup.py

Install PIP

Install dependencies First:

Yum Groupinstall "Development tools" Yum install zlib zlib-devel bzip2-devel openssl-devel
Sqlite-devel Readline-devel Tk-devel
wget--no-check-certificate https://github.com/pypa/pip/archive/1.5.5.tar.gz
tar zvxf 1.5.5.tar.gz   
CD pip-1.5.5/
python setup.py install
0x02 Installation Uwsgi
Pip Install Uwsgi

To create a profile in the root directory of the project:

Vim Config.ini

Fill in the following content:


Socket =     address and port used when starting the program
chdir =/home/www/          //Your project directory

wsgi-file = manage.py       // Flask Program Boot file

callable =              Application variable name

processes = 2//number of processors enabled in app//program

threads = 4                 // Number

of threads stats =      //Get service address for UWSGI statistics

For Wsgi's role in Web services, see here: Introduction to Python Wsgi

To start the service:

Uwsgi Config.ini
0x03 Installation Nginx

To configure the source and install:

Yum install yum-fastestmirror
yum install Nginx

To view the configuration file for Nginx application:


We need to change the location of the configuration file as follows (note that you need to change the place, the rest of the place according to your needs to change):

server {
        listen       ;
        server_name  www.test.com;  # Nginx will ignore this option when only one server is available, so just fill in the
        access_log  /logs/python.flask.access.log;  # Log Location

            include      uwsgi_params;
            Uwsgi_param Uwsgi_pyhome/usr/bin/python; # Point to the Virtual Environment directory (I do not use the virtual environment, write directly the location of the Python program)
            uwsgi_param uwsgi_chdir  /usr/apps/python/your_pro; # point to the site root directory
            Uwsgi_param Uwsgi_script Manage:app; # Specify startup program

Change the rest as needed.

After opening the UWSGI, continue to open the Nginx, the basic configuration is OK. 0x04 Installation Supervisor

After the above configuration, in fact, your site has been able to visit the normal, speed swish. But there are many times there will be accidents, uwsgi hang up how to do. This time you need a daemon program to help you restart it.

Supervisor is a process management tool, the popular point is to help you monitor a process, if found that it hung, immediately to continue it.


Pip Install Supervisor

Build configuration file:

./echo_supervisord_config >/etc/supervisord.conf

Next modify the configuration file, in the configuration file, the annotation character, and remove the preceding semicolon:

[Program:project_name]          # PROJECT_NAME for the project name command
= Uwsgi--ini/home/flask/config.ini  # Write the command to start UWSGI here, replace the config.ini path with an absolute path
stdout_logfile=/var/log/uwsgi/supervisor_flask.log      # Run Log
stderr_logfile=/var/log/uwsgi/supervisor_flask_err.log  # error log



Then look at the UWSGI process first:

PS aux | grep Uwsgi

Kill it, then PS to see the process is not:

Killall Uwsgi


Finally put on a picture of Meimei, the interface with the sister UI:

Reference Document:
http://www.cnblogs.com/dspace/archive/2016/07/06/ 5647587.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.