{"id":265874,"date":"2015-09-17T18:34:02","date_gmt":"2015-09-17T14:34:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=265874"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=265874","title":{"rendered":"\u0420\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u043c Flask-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0430 Nginx \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f Gunicorn"},"content":{"rendered":"<p>       \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c Ubuntu \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c Nginx \u0441 Flask-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c WSGI \u0441\u0435\u0440\u0432\u0435\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Gunicorn. Gunicorn (Green Unicorn) \u2014 WSGI HTTP \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Python \u0434\u043b\u044f UNIX \u0441\u0438\u0441\u0442\u0435\u043c. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 Onur G\u00fczel <a href=\"http:\/\/www.onurguzel.com\/how-to-run-flask-applications-with-nginx-using-gunicorn\/\">\u00abHow to Run Flask Applications with Nginx Using Gunicorn\u00bb<\/a>, \u0433\u0434\u0435 \u0448\u0430\u0433 \u0437\u0430 \u0448\u0430\u0433\u043e\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<hr\/>\n<p>  <\/p>\n<h2>\u0428\u0430\u0433 0: \u0422\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c virtualenv \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u043c \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435\u043c Python \u0438 pip \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 Python-\u043f\u0430\u043a\u0435\u0442\u0430\u043c\u0438. \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0438\u0445 \u0432\u0432\u0435\u0434\u044f \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"bash\">sudo apt-get install python-virtualenv python-pip <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0438 \u0430\u043a\u0442\u0438\u0432\u0438\u0440\u0443\u0435\u043c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"bash\">virtualenv hello source hello\/bin\/activate <\/code><\/pre>\n<p>  \u0417\u0430\u043c\u0435\u0447\u0430\u0435\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 prompt \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u044b.  <\/p>\n<hr\/>\n<p>  <\/p>\n<h2>\u0428\u0430\u0433 1: \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435<\/h2>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Flask:<\/p>\n<pre><code class=\"bash\">pip install Flask <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 Flask \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f pip, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432 <i>hello.py<\/i> \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0435\u0433\u043e:<\/p>\n<pre><code class=\"python\">from flask import Flask app = Flask(__name__) @app.route('\/') def hello():     return &quot;Hello world!&quot;   if __name__ == '__main__':     app.run() <\/code><\/pre>\n<p>  Flask \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0439 \u0432\u0435\u0431-\u0441\u0435\u0440\u0432\u0435\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u043e\u043d \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u044b\u043c \u0438 \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f production. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0435\u0441\u0442\u044c Gunicorn, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043e\u0442\u043e\u0432\u044b\u043c \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e \u0434\u043b\u044f production \u0438 \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u0435\u0442 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c.   <\/p>\n<hr\/>\n<p>  <\/p>\n<h2>\u0428\u0430\u0433 2: Gunicorn<\/h2>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c Gunicorn:<\/p>\n<pre><code class=\"bash\">pip install gunicorn <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0435 Flask-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u0441 Gunicorn, \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c 2 \u0438 9 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u043a\u043e\u0434\u0430 \u0432 <i>hello.py<\/i>:<\/p>\n<pre><code class=\"python\">from flask import Flask from werkzeug.contrib.fixers import ProxyFix app = Flask(__name__)   @app.route('\/') def hello():     return &quot;Hello world!&quot;  app.wsgi_app = ProxyFix(app.wsgi_app) if __name__ == '__main__':     app.run() <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 Gunicorn:<\/p>\n<pre><code class=\"bash\">gunicorn hello:app <\/code><\/pre>\n<p>  \u0413\u0434\u0435 <i>hello<\/i> \u044d\u0442\u043e \u0438\u043c\u044f python-\u0444\u0430\u0439\u043b\u0430(\u0431\u0435\u0437 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f). \u0418 <i>app<\/i> \u044d\u0442\u043e \u0438\u043c\u044f Flask-\u043e\u0431\u044a\u0435\u043a\u0442\u0430.   <\/p>\n<hr\/>\n<p>  <\/p>\n<h2>\u0428\u0430\u0433 3: Nginx<\/h2>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u0443\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043c \u0444\u0430\u0439\u043b \u0432:<br \/>  <i>\/etc\/nginx\/sites-available\/hello.conf<\/i><br \/>  \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 <i>hello.conf<\/i>:<\/p>\n<pre><code class=\"nginx\">server {     listen 80;     server_name hello.itu24.com;       root \/path\/to\/hello;       access_log \/path\/to\/hello\/logs\/access.log;     error_log \/path\/to\/hello\/logs\/error.log;       location \/ {         proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;         proxy_set_header Host $http_host;         proxy_redirect off;         if (!-f $request_filename) {             proxy_pass http:\/\/127.0.0.1:8000;             break;         }     } } <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u0441\u0441\u044b\u043b\u043a\u0443 \u0434\u043b\u044f \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 sites-enabled:<\/p>\n<pre><code class=\"bash\">sudo ln -s \/etc\/nginx\/sites-available\/hello.conf \/etc\/nginx\/sites-enabled\/ <\/code><\/pre>\n<p>  \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0438:<\/p>\n<pre><code class=\"bash\">nginx -t <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0435\u0439 \u0432\u0441\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c Nginx \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435.       <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/267097\/\"> http:\/\/habrahabr.ru\/post\/267097\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c Ubuntu \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0430\u0437\u0432\u0435\u0440\u043d\u0443\u0442\u044c Nginx \u0441 Flask-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u0412\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c WSGI \u0441\u0435\u0440\u0432\u0435\u0440, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Gunicorn. Gunicorn (Green Unicorn) \u2014 WSGI HTTP \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0430 Python \u0434\u043b\u044f UNIX \u0441\u0438\u0441\u0442\u0435\u043c. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e \u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 Onur G\u00fczel <a href=\"http:\/\/www.onurguzel.com\/how-to-run-flask-applications-with-nginx-using-gunicorn\/\">\u00abHow to Run Flask Applications with Nginx Using Gunicorn\u00bb<\/a>, \u0433\u0434\u0435 \u0448\u0430\u0433 \u0437\u0430 \u0448\u0430\u0433\u043e\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0440\u0430\u0437\u0432\u0435\u0440\u0442\u044b\u0432\u0430\u043d\u0438\u044f.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-265874","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=265874"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/265874\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=265874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=265874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=265874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}