日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx+uwsgi+flask配置记录

發(fā)布時間:2025/5/22 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx+uwsgi+flask配置记录 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??

nginx部分:

nginx使用nginx官方y(tǒng)um源 詳情:http://nginx.org/en/download.html

nginx的配置文件:

server {listen 80;server_name www.iday.me;access_log /var/log/nginx/iday.me.access.log main;error_log /var/log/nginx/iday.me.error.log ;location / {include uwsgi_params;uwsgi_pass unix:/dev/shm/iday.me;}location =/favicon.ico {alias /www/iday.me/static/img/favicon.ico;}location /static {alias /www/iday.me/static ;}}

uwsgi部分:

uwsgi通過pypi來來裝:

pip install uwsgi

配置uwsgi有些麻煩,把uwsgi源碼里的用于cenots的init.d script文件提取出來,稍作修改:

#!/bin/bash# uwsgi - Use uwsgi to run python and wsgi web apps. # # chkconfig: - 85 15 # description: Use uwsgi to run python and wsgi web apps. # processname: uwsgi# author: Roman Vasilyev# Source function library. . /etc/rc.d/init.d/functionsPATH=/opt/uwsgi:/sbin:/bin:/usr/sbin:/usr/bin prog=/usr/local/bin/uwsgiOWNER=nginxNAME=uwsgi DESC=uwsgiDAEMON_OPTS="--emperor '/etc/uwsgi/*.ini' --listen 1024 -d /var/log/uwsgi/$NAME.log --uid $OWNER -M --pidfile /var/run/$NAME.pid"[ -f /etc/sysconfig/uwsgi ] && . /etc/sysconfig/uwsgilockfile=/var/lock/subsys/uwsgistart () {echo -n "Starting $DESC: "daemon $prog $DAEMON_OPTSretval=$?echo[ $retval -eq 0 ] && touch $lockfilereturn $retval }stop () {echo -n "Stopping $DESC: "killproc $progretval=$?echo[ $retval -eq 0 ] && rm -f $lockfilereturn $retval }reload () {echo "Reloading $NAME" killproc $prog -HUPRETVAL=$?echo }force-reload () {echo "Reloading $NAME" killproc $prog -TERMRETVAL=$?echo }restart () {stopstart }rh_status () {status $prog }rh_status_q() {rh_status >/dev/null 2>&1 }case "$1" instart)rh_status_q && exit 0$1;;stop)rh_status_q || exit 0$1;;restart|force-reload)$1;;reload)rh_status_q || exit 7$1;;status)rh_status;;*) echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" >&2exit 2;;esacexit 0

然后用chkconfig 把uwsgi加入服務(wù)。這里我使用--emperor '/etc/uwsgi/*.ini' 參數(shù)即用 emperor模式來運行虛擬主機(jī)

配置uwsgi最麻煩的是虛擬主機(jī)的配置,uwsgi有virtualHosting模式,但是該模式只適合你有少量網(wǎng)站,而且它以一種相當(dāng)復(fù)雜的方式運行,并且很不安全。uwsgi建議使用emperor模式替代virtualhosting模式。

接下來只要把虛擬主機(jī)的配置文件放入/etc/uwsgi/目錄下就可以了,附上一個配置文件:iday.me.ini

[uwsgi] master max-requests =10000 processes = 2 pythonpath =/www/%n module =main callable=app enable-threads socket = /dev/shm/%n uid = nginx post-buffering=4096 logto=/var/log/uwsgi/%n.log pidfile=/var/run/uwsgi/%n.pid disable-logging listen=10240 ignore-sigpipe

?module=main 說的是flask項目的入口文件,main.py文件:

# -*- coding: utf-8 -*-import sys from models import * from views import * from app import app reload(sys) sys.setdefaultencoding('utf-8')if __name__ == '__main__':app.run(host='0.0.0.0',port=81)

最后講下面的uwsgi文件放入logrotate.d以便處理打包uwsgi產(chǎn)生的日志:

"/var/log/uwsgi/*.log" {copytruncatedailyrotate 5compressdelaycompressmissingoknotifempty }

轉(zhuǎn)載于:https://my.oschina.net/sol/blog/70677

總結(jié)

以上是生活随笔為你收集整理的nginx+uwsgi+flask配置记录的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。