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 杩涜甯冪讲

鎶€鏈浘鐗? src=

 

 

 

闃块噷浜戞湇鍔″櫒鎺у埗鍙帮細 https://www.aliyun.comhttps://ecs.console.aliyun.com/#/home

1銆佽繘鍏ユ帶鍒跺彴,鏌ョ湅瀹炰緥鍒涘缓鎯呭喌

鎶€鏈浘鐗? src=

2銆佺粰瀹夊叏缁勯厤缃鍒欙紝娣诲姞5000绔彛(涓€骞跺姞涓?001绔彛)

鎶€鏈浘鐗? src=

 

 

 鎶€鏈浘鐗? src=

 

 

 3銆佸埄鐢ㄥ懡浠よ杩涜杩滅▼鏈嶅姟鍣ㄧ櫥褰?/p>

ssh 鐢ㄦ埛鍚岪ip鍦板潃

鎶€鏈浘鐗? src=

鐩稿叧鐜瀹夎

浠ヤ笅鎿嶄綔閮藉湪杩滅▼鏈嶅姟鍣ㄤ笂杩涜鎿嶄綔 (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缃戠珯闃块噷浜戞湇鍔″櫒椤圭洰閮ㄧ讲的主要内容,如果未能解决你的问题,请参考以下文章

鍚屼竴涓猼omcat閮ㄧ讲澶氫釜椤圭洰瀵艰嚧鍚姩澶辫触

闃块噷浜戜富鏈猴紙ECS锛変笌CentOS7瀹炴垬

闃块噷寰湇鍔℃媶鍒?鏈嶅姟娌荤悊鍘熷垯

闃块噷宸村反寰湇鍔℃灦鏋勭殑鍥涘ぇ閲戝垰鍒╁櫒

缁囨ⅵ鏈湴璋冭瘯濂界殑缃戠珯鎬庝箞涓婁紶鍒版湇鍔″櫒