nginx+wsgi+flask configuration

WBOY
Release: 2016-07-29 08:57:54
Original
1161 people have browsed it

wsgi configuration file

<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>
Copy after login

tested 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>
Copy after login

run

<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>
Copy after login

nginx configuration

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

The above introduces the nginx+wsgi+flask configuration, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template