nginx+wsgi+flask配置

WBOY
发布: 2016-07-29 08:57:54
原创
1161 人浏览过

wsgi配置文件

<code>vim uwsgi.ini

[uwsgi]
<span>socket</span> = /tmp/t1.sock
<span>pidfile</span> = /tmp/t1.pid
<span>plugins</span> = python
<span>pythonpath</span> = /var/www
<span>#项目python环境</span><span>virtualenv</span> = /var/www/env
<span>#项目的跟路径</span><span>pythonpath</span> = /var/www/my_flask

<span>chdir</span> = /var/www/my_flask
<span>#日志文件</span><span>daemonize</span> = /var/www/my_flask/web.log
chmod-socket = 666

<span>master</span> = true
<span>#启动的进程</span><span>processes</span> = 4
<span>#环境变量</span><span>env</span>=PYTH/t1
<span>env</span>=LANG=zh_CN.UTF-8
<span>env</span>=LC_ALL=zh_CN.UTF-8

<span>#flask app的 py文件</span><span>module</span> = index
<span>#app的 py文件里面的app对象</span><span>callable</span> = app
max-requests = 500000
<span>#运行的用户</span><span>gid</span> = www-data
<span>uid</span> = www-data
ignore-sigpipe = true
enable-threads = true</code>
登录后复制

测试的index.py

<code><span>from</span> flask <span>import</span> Flask

app = Flask(__name__)

<span>@app.route("/")</span><span><span>def</span><span>hello</span><span>()</span>:</span><span>return</span><span>"Hello World!</span></code>
登录后复制

运行

<code><span>#以www-data用户运行 uwsgi </span>
sudo -u www-data uwsgi --ini uwsgi.ini 
<span>#运行后会生成socket文件</span>root<span>@ubuntu</span><span>:/var/www/my_flask</span><span># ll /tmp/t1*</span>
-rw-r--r-- <span>1</span> www-data www-data <span>5</span><span>Mar</span><span>21</span><span>10</span><span>:</span><span>13</span> /tmp/t1.pid
srw-rw-rw- <span>1</span> www-data www-data <span>0</span><span>Mar</span><span>21</span><span>10</span><span>:</span><span>13</span> /tmp/t1.sock=</code>
登录后复制

nginx配置

<code>server {
        <span>...</span>
        location / {
                include uwsgi_params;
                uwsgi_pass unix:///tmp/t1.sock; <span>#这为生成的sock文件</span>
        }
        <span>...</span>
}</code>
登录后复制
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了nginx+wsgi+flask配置,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板