日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

nginx+uwsgi+flask配置记录

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

為什么80%的碼農都做不了架構師?>>> ??

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加入服務。這里我使用--emperor '/etc/uwsgi/*.ini' 參數即用 emperor模式來運行虛擬主機

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

接下來只要把虛擬主機的配置文件放入/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產生的日志:

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

轉載于:https://my.oschina.net/sol/blog/70677

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。