Nginx+uwsgi+python+flask Environment Building —————— study notes

Source: Internet
Author: User

Build Environment Install dependency package

#yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel GroOP gd libXpm livxslt sqlite-devel

Installing Nginx

#yum -y install nginx

Start Nginx

#systemctl start nginx

Test Nginx

#ps -ef |grep nginx

Download python3.6 Compression Pack

#wget -c https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz

Installing python3.6

#tar -xvf Python-3.6.0.tgz
#cd Python-3.6.0
#./congigure --prefix=/usr/local/python3.6 && make && make install

Make a python3.6 link

#ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3

To modify an environment variable:

#vim ~/.bash_profile
PATH=$PATH:%HOME/bin:/usr/local/python3.6/bin

Test python3.6

python -V
Python 3.6.4

Installing the Python module using PIP must use PIP3 and compile the installed python3.6 with the PIP3

#rm -rf /usr/bin/pip
#ln -s /usr/local/python3.6/bin/pip3.6 /usr/bin/pip

Installing flask

#pip install flask

Create a project directory

#mkdir /root/flask_pro

Create a portal file

#vim /root/flask_pro/flask_app.py
from flask import Flask,request
app = Flask(__name__)Br/> ' @app. Route ('/helloworld/') '
def helloword()
return ‘helloword‘
if __name__ == ‘_main_‘ :
app.run(host=‘0.0.0.0‘,port=5000)

Run the Flask app

#python flask_app.py

Install Uwsgi:

pip install uwsgi

Configuration Uwsgi:

vim /root/flask_pro/uwsgi.ini
[uwsgi]
socket=127.0.01:5000
chdir=/root/flask_pro/
wsgi-file=flask_app.py
callable=app
processes=2
threads=2
buffer-size=65536

Modifying a configuration file

#vim /usr/local/nginx/conf/nginx.conf<br/>server { <br/> listen; <br/> server_name www.mdzzzz.cn; <br/> Location/{ <br/> include uwsgi_params; <br/> Uwsgi_pass 127.0.0.1:5000; <br/> } <br/> } `

Python load Uwsgi.ini

#uwsgi -d --ini /root/flask_pro/uwsgi.ini

Do boot start

#vim /etc/rc.local
uwsgi -d --ini /root/flask_pro/uwsgi.ini
#chmod +x /etc/rc.d/rc.local
#systemctl enable rc-local

Re-start Nginx

#systemctl restart nginx

Browser testing

http://www.mdzzzz,cn/helloworld/

Nginx+uwsgi+python+flask Environment Building —————— study notes

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.