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] # uwsgi Address and port used at startup (may not be consistent with project port) socket = 127.0.0.1:5000 # Point to the website directory chdir=/usr/local/nginx/html/myblog # 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 = 127.0.0.1:9191
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_pass 127.0.0.1:5000; 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 services7. 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.
done.