{"id":670,"date":"2018-02-24T16:22:13","date_gmt":"2018-02-24T08:22:13","guid":{"rendered":"http:\/\/60.205.208.74\/?p=670"},"modified":"2018-02-24T16:22:13","modified_gmt":"2018-02-24T08:22:13","slug":"python-web-application-deploy-using-uwsgi-ubuntu","status":"publish","type":"post","link":"https:\/\/www.puzi7.net\/?p=670","title":{"rendered":"Python Web application deploy using uWSGI in ubuntu"},"content":{"rendered":"<span itemprop=\"description\"><p style=\"font-size: 14px;\">\u5b89\u88c5\u73af\u5883\uff1a<\/p>\n<ul>\n<li>Mac(10.9) + nginx(1.4.7) + python(2.7.5) + uwsgi(2.0.4) + django-cms(2.4.3)<\/li>\n<li>\u4f7f\u7528supervisord\u505a\u540e\u53f0\u5b88\u62a4\u8fdb\u7a0b<\/li>\n<li>\u9ed8\u8ba4\u7cfb\u7edf\u5df2\u7ecf\u5b89\u88c5python, nginx<\/li>\n<\/ul>\n<p>\u4f7f\u7528virtualenv \u4f5c\u4e3apython\u90e8\u7f72\u73af\u5883<\/p>\n<ol>\n<li>\u5b89\u88c5virtualenv \u00a0 easy_install virtualenv<\/li>\n<li>\u5b89\u88c5pip \u00a0easy_install pip<\/li>\n<li>\u521b\u5efapython\u865a\u62df\u73af\u5883 \u00a0virtualenv .env<\/li>\n<li>\u4f7f\u7528\u865a\u62df\u73af\u5883 \u00a0 source .env\/bin\/activate<\/li>\n<li>\u5b89\u88c5django-cms \u00a0 pip install django-cms==2.4.3(\u5b89\u88c5\u7a0b\u5e8f\u597d\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56\u7684\u5bf9\u5e94\u7248\u672c\u7684\u63d2\u4ef6\uff0cdjango\uff0csouth\u3002\u3002\u3002)<\/li>\n<li>\u5b89\u88c5uwsgi pip install uWSGI<\/li>\n<li>\u5b89\u88c5supervisord pip install supervisor<\/li>\n<li>\u521b\u5efadjango-cms\u9879\u76ee \u00a0 \u00a0 django-admin.py startproject demo<\/li>\n<li>\u4f7f\u7528\u9ed8\u8ba4\u7684\u65b9\u5f0f\u8fd0\u884c\u9879\u76ee \u00a0 cd demo &amp;&amp; python manage.py runserver<\/li>\n<li>\u8bbf\u95eehttp:\/\/localhost:8000\u67e5\u770b\u9875\u9762\u662f\u5426\u6b63\u5e38<\/li>\n<li>\u4f7f\u7528uwsgi \u542f\u52a8\u9879\u76ee \u00a0 uwsgi &#8211;socket 127.0.0.1:9001 &#8211;protocol http &#8211;chdir \u9879\u76ee\u7684\u76ee\u5f55 \u00a0&#8211;venv .env &#8211;wsgi-file demo\/demo\/wsgi.py<\/li>\n<li>\u914d\u7f6esupervisor\u6765\u540e\u53f0\u5b88\u62a4uwsgi\u8fdb\u7a0b \u00a0 ,\u5c3d\u91cf\u4f7f\u7528\u9ed8\u8ba4\u914d\u7f6e<\/li>\n<\/ol>\n<pre class=\"shell\">[program:demo]\ncommand= .env\/bin\/uwsgi \n    --protocal=http\n    --socket=127.0.0.1:9001\n    --chdir=Projects\/Python\/demo\n    --wsgi-file=rojects\/Python\/demo\/demo\/wsgi.py\n    --venv=Projects\/Python\/.env\n    --processes=2\n\nautostart=true                ; start at supervisord start (default: true)\nstopsignal=INT               ; signal used to kill process (default TERM)\nstdout_logfile_maxbytes=10MB   ; max # logfile bytes b4 rotation (default 50MB)\nstdout_logfile_backups=10     ; # of stdout logfile backups (default 10)\nstderr_logfile_maxbytes=10MB   ; max # logfile bytes b4 rotation (default 50MB)\nstderr_logfile_backups=10     ; # of stderr logfile backups (default 10)<\/pre>\n<p style=\"font-size: 14px;\">\u00a013. \u8fd0\u884csupervisord \u00a0sudo supervisord -c \/etc\/supervisord.conf<\/p>\n<p style=\"font-size: 14px;\">\u00a014. \u4f7f\u7528nginx \u505a\u524d\u7aef\u8f6c\u53d1<\/p>\n<pre class=\"shell\">location \/ {\n    include uwsgi_params;\n    proxy_pass  http:\/\/127.0.0.1:9001;\n}<\/pre>\n<p style=\"font-size: 14px;\">\u00a0 15. \u8bbf\u95ee\u9875\u9762\u770b\u6548\u679c<\/p>\n<p style=\"font-size: 14px;\">\n<p style=\"font-size: 14px;\">\u9047\u5230\u7684\u95ee\u9898\uff1a<\/p>\n<ol>\n<li><span style=\"line-height: 21px;\">no loaded app \u00a0:\u89e3\u51b3\u65b9\u6cd5 \u4e0d\u8981\u4f7f\u7528 \u00a0-s , \u9700\u8981\u4f7f\u7528&#8211;socket \u00a0\u548cprotocol, \u5e76\u4e14\u6307\u5b9awsgi-file<\/span><\/li>\n<li><span style=\"line-height: 21px;\">supervisorctl \u65e0\u6cd5\u542f\u52a8 \u663e\u793aunload confignation from &#8230;, \u9879\u76ee\u7684\u8def\u5f84\u5e94\u8be5\u662f\u7edd\u5bf9\u8def\u5f84\uff0c\u4e0d\u80fd\u662f\u8f6f\u8fde\u63a5<\/span><\/li>\n<li><span style=\"line-height: 21px;\">\u5982\u679cnginx\u65e0\u6cd5\u4f7f\u7528uwsgi_pass, \u53ef\u4ee5\u4f7f\u7528proxy_pass \u505a\u53cd\u5411\u4ee3\u7406<\/span><\/li>\n<\/ol>\n<p style=\"font-size: 14px;\">\u53c2\u8003\uff1ahttps:\/\/uwsgi-docs.readthedocs.org\/en\/latest\/tutorials\/Django_and_nginx.html<\/p>\n<span>","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\"><span itemprop=\"description\">\u5b89\u88c5\u73af\u5883\uff1a Mac(10.9) + nginx(1.4.7) + python(2.7.5&hellip;<\/span><\/p>\n<p class=\"more-link-p btn-align-right\"><a class=\"green zoom-btn\" href=\"https:\/\/www.puzi7.net\/?p=670\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,13],"tags":[96,106,117,123,125],"class_list":["post-670","post","type-post","status-publish","format-standard","hentry","category-9","category-blog","category-13","tag-nginx","tag-python","tag-supervisord","tag-uwsgi","tag-virtualenv","zoom-theme-has-thumb"],"_links":{"self":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=670"}],"version-history":[{"count":0,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=\/wp\/v2\/posts\/670\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.puzi7.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}