CentOS7.2安裝配置nginx+flask+python+uwsgi運行環境

來源:互聯網
上載者:User

標籤:程式設計語言   Python   

作業系統:CentOS 7.2

Nginx安裝請參考centos7.2安裝nginx這個文章

1. 安裝python3.5

執行命令

wget --no-check-certificate https://www.python.org/ftp/python/3.5.0/Python-3.5.0.tgz

等待下載完成

下載完成後,執行tar -zxvf Python-3.5.0.tgz解壓安裝包,因檔案太多,只取最後幾個

Cd到python的解壓目錄下執行./configure命令,同樣只取最後幾行

然後執行make & make install命令

安裝完成後,執行python3命令

證明python3.5安裝完成

2. 安裝setuptools和pip

安裝setuptools,先下載

wget --no-check-certificate? https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

下載完成後,解壓檔案

tar -zxvf setuptools-19.6.tar.gz

Cd到解壓後的檔案夾中,與Python3安裝不同,需要執行如下兩個命令

Python3 setup.py build

Python3 setup.py install

安裝完成

安裝pip

同樣,先下載

wget --no-check-certificate? https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

解壓檔案tar -zxvf pip-8.0.2.tar.gz

然後依次執行

cd pip-8.0.2

python3 setup.py build

python3 setup.py install

完成安裝

輸入pip測試是否安裝成功,返回

cannot import name ‘HTTPSHandler‘

解決方案,安裝openssl和openssl-devel

執行yum install opessl和yum install openssl-devel

完裝完成後,重新在python3.5目錄下執行./configure , make, make install命令

再次執行pip,完成安裝

3. 安裝flask

執行pip install flask

執行flask,驗證flask是否安裝成功

用vim建立一個hello.py的檔案,copy下面的內容到檔案中

from flask import Flask

app = Flask(__name__)

@app.route("/")

def hello():

??? return "Hello World!"

if __name__ == "__main__":

??? app.run(host=‘0.0.0.0‘, port=8080)

然後執行python3 hello.py

運行效果:

4. 安裝uwsgi

執行pip install uwsgi

安裝完成

用vim建立uwsgi.ini檔案,把下面的內容copy到檔案中

[uwsgi]

socket = 172.20.10.11:8080

chdir = /www

wsgi-file = /www/hello.py

callable = app

processes = 4

threads = 2

pythonpath = /www

修改nginx設定檔/usr/local/nginx/conf/nginx.conf

重啟uwsgi和nginx,訪問http://172.20.10.11,效果如下:

到此CentOS+nginx+uwsgi+flask運行環境搭建完成

CentOS7.2安裝配置nginx+flask+python+uwsgi運行環境

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.