程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python crawler practice -- Chapter 3: deploy flask project to ECS

編輯:Python

This practical project has passed python Crawling for Douban movie Top250 The list , utilize flask frame and Echarts Chart analysis score 、 Release year and visualize results , And made word cloud , The project has been uploaded to the server , Welcome to criticize and correct .

Project presentation :http://121.36.81.197:5000/
Source code address :https://github.com/lzz110/douban_movies_top250
Learning materials :Python Reptile technology 5 It's a quick success (2020 New collection )

Project technology stack :Flask frame 、Echarts、WordCloud、SQLite
Environmental Science :Python3

Last chapter The data has been analyzed and visualized , This chapter deploys the project to the server , Convenient view .

The server : Huawei cloud Kunpeng server
System :Ubuntu18.04 Server
Python:Python3.6.7
pip:pip 19.1.1
uwsgi:2.0.18
Nginx: 1.14.0

The steps mainly refer to the blog :Flask Deploy Huawei Kunpeng ECs

Pay attention to one : Generate requirements.txt file
In local projects Terminal Enter the command at the command line , Under the same level directory, a requirements.txt The file

pip freeze > requirements.txt

Attention two : ECS needs to open the corresponding security group



After opening the corresponding port , You can use the... In the server nginx To test Enter the public network in the browser ip after The browser will display the following pages :
Note three : Nginx+UWSGI Configuration problem

uWSGI It's a by python Realized web Containers , It can be released with good compatibility Django,Flask etc. pythonweb Application of framework . Because essentially uwsgi yes python A module of , So it can be used pip install uwsgi Install it directly .

A typical configuration file is as follows :

[uwsgi]
socket = 127.0.0.1:5000
pythonpath = /home/wyz/flask
module = manage
wsgi-file = /home/wyz/flask/manage.py
callable = app
processes = 4
threads = 2
daemonize = /home/wyz/flask/server.log

Explain these configuration items in turn .socket Point out a socket , It's equivalent to leaving a space for the outside world uwsgi The interface to the server . It should be noted that ,socket It's not equal to http. In other words, it is configured with this uwsgi The server is not able to pass directly http Requesting successful access .

About socket and http The difference between Conceptually speaking ,socket It's not an agreement in itself, it's a concrete TCP/IP Realization way , and HTTP It's a protocol and it's based on TCP/IP.
Let's talk about this configuration , If I only have socket = 127.0.0.1:5000 Words , Through a browser or something HTTP Means cannot be successfully accessed . And in the uwsgi The log here will indicate that the length of the request packet exceeds the maximum fixed length .
On the other hand , If you are configuring http = 127.0.0.1:5000 Words , Then you can go directly through the general http Means to access the target . But it can cause nginx Not working properly . The right thing to do is , If there is nginx stay uwsgi As an agent before, it should be equipped with socket, And if you want the request to go straight to uwsgi If you want to go with http.

Notice four : Use nohup After running the program in the background You can't just shut it down MobaXterm , You need to wait for yourself to disconnect , If you close it directly The program will not run in the background I'm fascinated ……

Refer to the post :

  1. uWSGI+Nginx+Flask stay Linux Next deployment
  2. 【Flask】 utilize uWSGI and Nginx Release Flask application
  3. Nginx+UWSGI Configuration problem

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved