web缃戠珯闃块噷浜戞湇鍔″櫒椤圭洰閮ㄧ讲
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了web缃戠珯闃块噷浜戞湇鍔″櫒椤圭洰閮ㄧ讲相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/www' title='www'>www height ati start 鏂囦欢 mysq nbsp pst 淇℃伅
椤圭洰閮ㄧ讲
鍩轰簬ubuntu 16.04绯荤粺锛屼娇鐢?Gunicorn + nginx 杩涜甯冪讲
闃块噷浜戞湇鍔″櫒鎺у埗鍙帮細 https://www.aliyun.comhttps://ecs.console.aliyun.com/#/home
1銆佽繘鍏ユ帶鍒跺彴,鏌ョ湅瀹炰緥鍒涘缓鎯呭喌
2銆佺粰瀹夊叏缁勯厤缃鍒欙紝娣诲姞5000绔彛(涓€骞跺姞涓?001绔彛)
3銆佸埄鐢ㄥ懡浠よ杩涜杩滅▼鏈嶅姟鍣ㄧ櫥褰?/p>
ssh 鐢ㄦ埛鍚岪ip鍦板潃
鐩稿叧鐜瀹夎
浠ヤ笅鎿嶄綔閮藉湪杩滅▼鏈嶅姟鍣ㄤ笂杩涜鎿嶄綔 (ubuntu 16.04)
1锛夊厛鏇存柊 apt 鐩稿叧婧?/p>
sudo apt-get update
2锛塵ysql瀹夎
apt-get install mysql-server apt-get install libmysqlclient-dev
3锛塺edis瀹夎
sudo apt-get install redis-server
4锛夊畨瑁呰櫄鎷熺幆澧?/p>
pip install virtualenv
pip install virtualenvwrapper
浣垮緱瀹夎鐨剉irtualenvwrapper鐢熸晥锛岀紪杈憕/.bashrc鏂囦欢锛屽唴瀹瑰涓?
export WORKON_HOME=$HOME/.virtualenvs export PROJECT_HOME=$HOME/workspace source /usr/local/bin/virtualenvwrapper.sh
閲嶆柊鍔犺浇鏂囦欢锛屼娇鏂囦欢鐢熸晥
source ~/.bashrc
4銆乺equirements鏂囦欢
Python 椤圭洰涓彲浠ュ寘鍚竴涓?requirements.txt 鏂囦欢锛岀敤浜庤褰曟墍鏈変緷璧栧寘鍙婂叾绮剧‘鐨勭増鏈彿锛屼互渚垮湪鏂扮幆澧冧腑杩涜閮ㄧ讲鎿嶄綔銆?/p>
- 鍦ㄨ櫄鎷熺幆澧冧娇鐢ㄤ互涓嬪懡浠ゅ皢褰撳墠铏氭嫙鐜涓殑渚濊禆鍖呬互鐗堟湰鍙风敓鎴愯嚦鏂囦欢涓細
pip freeze > requirements.txt
- 褰撻渶瑕佸垱寤鸿繖涓櫄鎷熺幆澧冪殑瀹屽叏鍓湰锛屽彲浠ュ垱寤轰竴涓柊鐨勮櫄鎷熺幆澧冿紝骞跺湪鍏朵笂杩愯浠ヤ笅鍛戒护锛?/li>
1 pip install -r requirements.txt
鍦ㄥ畨瑁?Flask-MySQLdb 鐨勬椂鍊欏彲鑳戒細鎶ラ敊锛屽彲鑳芥槸渚濊禆鍖呮病鏈夊畨瑁咃紝鎵ц浠ヤ笅鍛戒护瀹夎渚濊禆鍖咃細
sudo apt-get build-dep python-mysqldb
5銆丯ginx瀹夎
- 閲囩敤 C 璇█缂栧啓
- 瀹炵幇鍒嗘祦銆佽浆鍙戙€佽礋杞藉潎琛?/li>
瀹夎
$ sudo apt-get install nginx
杩愯鍙婂仠姝?/p>
/etc/init.d/nginx start #鍚姩 /etc/init.d/nginx stop #鍋滄
閰嶇疆鏂囦欢
- 缂栬緫鏂囦欢:/etc/nginx/sites-available/default
# 濡傛灉鏄鍙版湇鍔″櫒鐨勮瘽锛屽垯鍦ㄦ閰嶇疆锛屽苟淇敼 location 鑺傜偣涓嬮潰鐨?proxy_pass upstream flask { server 127.0.0.1:5000; server 127.0.0.1:5001; } server { # 鐩戝惉80绔彛 listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name _; location / { # 璇锋眰杞彂鍒癵unicorn鏈嶅姟鍣?/span> proxy_pass http://127.0.0.1:5000; # 璇锋眰杞彂鍒板涓猤unicorn鏈嶅姟鍣?/span> # proxy_pass http://ip:port; # 璁剧疆璇锋眰澶达紝骞跺皢澶翠俊鎭紶閫掔粰鏈嶅姟鍣ㄧ proxy_set_header Host $host; # 璁剧疆璇锋眰澶达紝浼犻€掑師濮嬭姹俰p缁?gunicorn 鏈嶅姟鍣?/span> proxy_set_header X-Real-IP $remote_addr; } }
6銆丟unicorn
- Gunicorn锛堢豢鑹茬嫭瑙掑吔锛夋槸涓€涓狿ython WSGI鐨凥TTP鏈嶅姟鍣?/li>
- 浠嶳uby鐨勭嫭瑙掑吔锛圲nicorn 锛夐」鐩Щ妞?/li>
- 璇unicorn鏈嶅姟鍣ㄤ笌鍚勭Web妗嗘灦鍏煎锛屽疄鐜伴潪甯哥畝鍗曪紝杞婚噺绾х殑璧勬簮娑堣€?/li>
- Gunicorn鐩存帴鐢ㄥ懡浠ゅ惎鍔紝涓嶉渶瑕佺紪鍐欓厤缃枃浠?/li>
瀹夎
pip install gunicorn
鏌ョ湅閫夐」
gunicorn -h
杩愯
# -w: 琛ㄧず杩涚▼锛坵orker锛?-b锛氳〃绀虹粦瀹歩p鍦板潃鍜岀鍙e彿锛坆ind锛?/span> gunicorn -w 2 -b 127.0.0.1:5000 杩愯鏂囦欢鍚嶇О:app绋嬪簭瀹炰緥鍚?/pre>
鍙傝€冮槄璇伙細 Gunicorn鐩稿叧閰嶇疆锛?a href="https://blog.csdn.net/y472360651/article/details/78538188" target="_blank">https://blog.csdn.net/y472360651/article/details/78538188
鍏朵粬鎿嶄綔
- 鎷疯礉鏈湴浠g爜鍒拌繙绋?/li>
scp -r 鏈湴鏂囦欢璺緞 root@ip:杩滅▼淇濆瓨璺緞
以上是关于web缃戠珯闃块噷浜戞湇鍔″櫒椤圭洰閮ㄧ讲的主要内容,如果未能解决你的问题,请参考以下文章