centos server deploys flask project.

Installed environments nginx, Python 3, mysql, uwsgi, virtualenv

1. Create a virtual environment

virtualenv -p python3 myblog

2. Enter the Virtual Environment

source myblog/bin/activate

3. Install flask and uwsgi in virtual environment

pip install flask
pip install uwsgi

4. Configure uwsgi, create the configuration file uwsgiconfig.ini under the root directory of the deployment project, and add the following configuration

# uwsgi Address and port used at startup (may not be consistent with project port)
socket =
# Point to the website directory
# python Starter file
wsgi-file = myblog.py
# python The program used to start application Variable name
callable = app
# Processor number
processes = 4
# Thread count
threads = 2
# Buffer
buffer-size = 32768
#Status Detection Address
stats =

5. Configure nginx and add the following:

server {
     listen          80;
     server_name     www.myblog.terroristhouse.com;  # Aliyun Public Network ip
    location / {
            include uwsgi_params;
            uwsgi_param UWSGI_PYHOME /root/myblog;  #python position,Either a virtual machine or a running environment variable location
            uwsgi_param UWSGI_CHDIR /usr/local/nginx/html/myblog;  #Project root directory
            uwsgi_param UWSGI_SCRIPT myblog:app;    #Start the main program of the project,If manage.py Bit field flask-prj Of src/flask/In such a catalogue, it will be written as src/flask/manage:app such
            #root   /usr/share/nginx/html;
            #index  index.html index.htm;

6. Restart nginx

Kill all-9 nginx to close the process of nginx
/ usr/local/nginx/sbin/nginx to start and view nginx services

7. Running uwsgi services

uwsgi --ini /usr/local/nginx/html/myblog/uwsgiconfig.ini

#Background operation
uwsgi --ini /usr/local/nginx/html/myblog/uwsgiconfig.ini --daemonize /usr/local/nginx/html/myblog/myblog.out

Note: The project operation method should be changed to manage.app()

Enter the domain name to access the website.



Tags: Python Nginx pip MySQL

Posted on Thu, 03 Oct 2019 10:08:07 -0400 by A3aan