{"id":6912,"date":"2013-06-16T08:22:52","date_gmt":"2013-06-15T23:22:52","guid":{"rendered":"http:\/\/www.ekesete.net\/log\/?p=6912"},"modified":"2014-01-08T20:52:05","modified_gmt":"2014-01-08T11:52:05","slug":"django%e3%82%92%e4%bd%bf%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%8b-%e3%81%9d%e3%81%ae2-nginx%e3%81%a8uwsgi%e3%81%ae%e8%a8%ad%e5%ae%9a","status":"publish","type":"post","link":"https:\/\/www.ekesete.net\/log\/?p=6912","title":{"rendered":"Django\u3092\u4f7f\u3063\u3066\u307f\u308b \u305d\u306e2 &#8211; nginx\u3068uWSGI\u306e\u8a2d\u5b9a"},"content":{"rendered":"<p>\u57fa\u672c\u7684\u306a\u3068\u3053\u308d\u306f\u52d5\u304b\u305b\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u6b21\u306fnginx\u3068uWSGI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3001\u8a2d\u5b9a\u3092\u884c\u3063\u3066\u5916\u304b\u3089\u898b\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<br \/>\n\u3053\u306e\u3042\u305f\u308a\u306f\u524d\u306bpython\u3092uWSGI\u7d4c\u7531\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3088\u3046\u3068\u601d\u3063\u305f\u6642\u306b\u3001\u672c\u4f53\u3068\u3042\u307e\u308a\u95a2\u4fc2\u306a\u3044\u306e\u306b\u3088\u304f\u308f\u304b\u3089\u306a\u304f\u3066\u3084\u308b\u6c17\u3092\u304b\u306a\u308a\u524a\u304c\u308c\u305f\u3068\u3053\u308d\u3067\u3059(\u7b11<br \/>\n\u66f8\u3044\u3066\u307f\u308b\u3068\u305d\u3053\u307e\u3067\u3067\u306f\u306a\u3044\u3067\u3059\u306d\u3002\u305f\u3060\u3057\u6bce\u5ea6\u306e\u3054\u3068\u304f\u6b63\u78ba\u306a\u5185\u5bb9\u304b\u3069\u3046\u304b\u306e\u4fdd\u8a3c\u306f\u3067\u304d\u307e\u305b\u3093\u304c\u2026\u2026<\/p>\n<p>\u4eca\u56de\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u305f\u30d0\u30fc\u30b8\u30e7\u30f3\u306f<br \/>\nnginx 1.4.1<br \/>\nuWSGI 1.9.12<br \/>\n\u3067\u3059\u3002<\/p>\n<h4>nginx\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u8a2d\u5b9a<\/h4>\n<p>ports\u306ewww\/nginx\u306b\u3042\u308b\u306e\u3067\u7279\u306bconfig\u3082\u5909\u66f4\u3057\u306a\u3044\u3067\u3053\u3053\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3057\u305f\u3002<br \/>\n\/etc\/rc.conf\u306b\u3082nginx_enable=&#8221;yes&#8221;\u3092\u8ffd\u52a0\u3057\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306f\/usr\/local\/etc\/nginx\u306b\u3042\u308b\u306e\u3067uWSGI\u3068\u63a5\u7d9a\u3059\u308b\u8a2d\u5b9a\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<br \/>\nnginx.conf\u306elocation\u90e8\u5206\u3092\u5909\u66f4<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">&nbsp; &nbsp; server {<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; listen &nbsp; &nbsp; &nbsp; 80;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; server_name &nbsp;localhost;<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; #charset koi8-r;<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; #access_log &nbsp;logs\/host.access.log &nbsp;main;<br \/>\n<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; location \/ {<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uwsgi_pass 127.0.0.1:49152;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; include uwsgi_params;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; }<\/div><\/div>\n<p>uWSGI\u3068\u306f127.0.0.1:49152\u3067\u30c7\u30fc\u30bf\u306e\u3084\u308a\u3068\u308a\u3092\u3059\u308b\u3053\u3068\u306b\u3057\u307e\u3059\u3002uWSGI\u5074\u3082\u3042\u3068\u3067\u5408\u308f\u305b\u305f\u8a2d\u5b9a\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>rc.conf\u306b\u3082\u66f8\u3044\u305f\u306e\u3067nginx\u306f\u6700\u8d77\u52d5\u6642\u306b\u7acb\u3061\u4e0a\u304c\u308a\u307e\u3059\u304c\u3001\u624b\u52d5\u3067\u8d77\u52d5\u3059\u308b\u5834\u5408\u306f<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">\/usr\/local\/etc\/rc.d\/nginx start<\/div><\/div>\n<p>\u3000<\/p>\n<h4>uWSGI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u8a2d\u5b9a<\/h4>\n<p>\u4eee\u60f3\u74b0\u5883\u306bpip\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3002<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">[testenv] %pip install uwsgi<\/div><\/div>\n<p>\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306ftestenv\u306e\u4e0b\u306betc\/wsgi.ini\u3068\u3057\u3066\u4f5c\u308a\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u5185\u5bb9\u3092\u8a18\u8ff0\u3002<br \/>\nini\u30d5\u30a1\u30a4\u30eb\u306f\u3069\u3053\u306b\u7f6e\u304f\u306e\u304c\u826f\u3044\u306e\u304b\u306f\u308f\u304b\u308a\u307e\u305b\u3093\u304c\u3001\u4eee\u60f3\u74b0\u5883\u4e0b\u306bbin\u304c\u4f5c\u6210\u3055\u308c\u308b\u306e\u3067\u540c\u3058\u3088\u3046\u306a\u611f\u3058\u3067etc\u3092\u4f5c\u308b\u3053\u3068\u306b\u3057\u307e\u3057\u305f\u3002<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">[uwsgi]<br \/>\nsocket = 127.0.0.1:49152<br \/>\nprocesses = 5<br \/>\nmaster = true<br \/>\nchdir = \/home\/ichinomoto\/testenv\/testproject<br \/>\nmodule = testproject.wsgi:application<br \/>\nharakiri = 20<br \/>\nmax-requests = 5000<br \/>\nvacuum = true<br \/>\npidfile=var\/testproject.pid<br \/>\ndaemonize=var\/testproject.log<\/div><\/div>\n<p>socket\u306fnginx.conf\u306euwsgi_pass\u306b\u66f8\u3044\u305f\u7269\u3068\u540c\u3058\u306b\u3057\u307e\u3059\u3002\u30b5\u30a4\u30c8\u306b\u3088\u3063\u3066\u306f\/tmp\/testproject.sock\u306e\u3088\u3046\u306b\u30d5\u30a1\u30a4\u30eb\u306b\u3057\u3066\u3042\u308b\u3068\u3053\u308d\u3082\u3042\u308a\u307e\u3059\u304c\u3001\u305d\u306e\u5834\u5408nginx.conf\u306b\u3042\u308buwsgi_pass\u306e\u66f8\u304d\u65b9\u304c&#8221;wsgi_pass unix:\/\/\/tmp\/testproject.sock&#8221;\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002\u8a73\u7d30\u306f\u4ed6\u306e\u30b5\u30a4\u30c8\u3092\u53c2\u7167\u306e\u3053\u3068\u3002<br \/>\n\u8a2d\u5b9a\u304c\u56fa\u307e\u308b\u307e\u3067\u306f\u30d5\u30a9\u30a2\u30b0\u30e9\u30a6\u30f3\u30c9\u3067\u52d5\u304b\u3057\u3066\u304a\u304f\u305f\u3081\u306b\u6700\u5f8c\u306edaemonize\u306f\u5916\u3057\u305f\u65b9\u304c\u826f\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<br \/>\n\u306a\u304a\u3001\u3053\u306e\u8a2d\u5b9a\u306b\u3059\u308b\u306e\u3067\u3042\u308c\u3070pid\u30d5\u30a1\u30a4\u30eb\u3068daemonize\u306b\u66f8\u3044\u305f\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u305f\u3081\u306bvirtualenv\u306e\u4e0b\u306bvar\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002<\/p>\n<p>\u8d77\u52d5\u6642\u306b\u306f\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<br \/>\n\u306a\u304a\u3001pid\u3068\u30ed\u30b0\u30d5\u30a1\u30a4\u30eb\u306e\u4f4d\u7f6e\u306f\u76f8\u5bfe\u30d1\u30b9\u306b\u306a\u308b\u306e\u3067virtualenv\u306e\u76f4\u4e0b\u304b\u3089\u8d77\u52d5\u3059\u308b\u524d\u63d0\u3067\u66f8\u3044\u3066\u3042\u308a\u307e\u3059\u3002\u8d77\u52d5\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u3044\u3066bin\u306e\u4e0b\u306b\u7f6e\u3044\u3066\u304a\u304f\u306a\u3069\u3057\u305f\u65b9\u304c\u826f\u3044\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">[testenv] %uwsgi --ini etc\/wsgi.ini<\/div><\/div>\n<p>\u505c\u6b62\u306f\u3001\u30d5\u30a9\u30a2\u30b0\u30e9\u30a6\u30f3\u30c9\u306a\u3089Ctrl-C\u3067\u3002<br \/>\ndaemonize=var\/testproject.log\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u308b\u5834\u5408\u306b\u306fQUIT\u30b7\u30b0\u30ca\u30eb\u3092\u9001\u308a\u307e\u3059\u3002<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">%kill -QUIT `cat var\/testproject.pid`<\/div><\/div>\n<p>\u3053\u3053\u307e\u3067\u3067\u304d\u305f\u3089\u3042\u3068\u306f\u4e2d\u8eab\u3092\u4f5c\u308b\u3053\u3068\u306b\u5c02\u5ff5\u3067\u304d\u307e\u3059\u3002<br \/>\n\u3000<\/p>\n<p>[\u8ffd\u8a18]<br \/>\n\u9762\u5012\u306a\u306e\u3067\u7d50\u5c40\u8d77\u52d5\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u4f5c\u308a\u307e\u3057\u305f\u3002<br \/>\n\u3053\u308c\u3092\u4f7f\u3046\u5834\u5408\u306fwsgi.ini\u306b\u3042\u308bpidfile\u884c\u3068daemonize\u884c\u304c\u304b\u3076\u308b\u306e\u3067\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br \/>\nvitualenv\u306ebin\u306e\u4e0b\u306btestenv_ctrl.sh\u3068\u3057\u3066\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;height:300px;\"><div class=\"text codecolorer\">#!\/bin\/sh<br \/>\n<br \/>\nvirtualenv_dir=&quot;\/home\/ichinomoto\/testenv\/&quot;<br \/>\nwsgi_ini=&quot;${virtualenv_dir}etc\/wsgi.ini&quot;<br \/>\nwsgi_pid=&quot;${virtualenv_dir}var\/testproject.pid&quot;<br \/>\nwsgi_log=&quot;${virtualenv_dir}var\/testproject.log&quot;<br \/>\n<br \/>\nstart(){<br \/>\n&nbsp; &nbsp; echo &quot;uWSGI testproject start&quot;<br \/>\n&nbsp; &nbsp; uwsgi --ini $wsgi_ini --daemonize $wsgi_log --pidfile $wsgi_pid<br \/>\n}<br \/>\n<br \/>\nstop(){<br \/>\n&nbsp; &nbsp; echo &quot;uWSGI testproject stop&quot;<br \/>\n&nbsp; &nbsp; kill -QUIT `cat $wsgi_pid`<br \/>\n}<br \/>\n<br \/>\ncase &quot;$1&quot; in<br \/>\n&nbsp; &nbsp; start)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; start<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ;;<br \/>\n&nbsp; &nbsp; stop)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; stop<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ;;<br \/>\n&nbsp; &nbsp; restart)<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; stop<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; start<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; ;;<br \/>\nesac<\/div><\/div>\n<p>virtualenv\u74b0\u5883\u306b\u5165\u308c\u3070\u30d1\u30b9\u304c\u901a\u3063\u305f\u72b6\u614b\u306b\u306a\u308b\u306e\u3067<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">[testenv] %testenv_ctrl.sh start<\/div><\/div>\n<p>\u3067\u8d77\u52d5\u3067\u304d\u307e\u3059\u3002\u3042\u3068stop\u3068restart\u3082\u3002<br \/>\n\u3000<br \/>\n\u3000<br \/>\n[\u53c2\u8003]<br \/>\n\u4eee\u60f3\u74b0\u5883\u3067\u306f\u306a\u304fFreeBSD\u672c\u4f53\u5074\u306buwsgi\u3092\u5165\u308c\u308b\u5834\u5408\u306e\u53c2\u8003\u306b\u3002<br \/>\n<a href=\"http:\/\/www.andrewjo.com\/blog\/web-development\/freebsd-django-nginx-uwsgi\" target=\"_blank\">FreeBSD + Django + nginx + uWSGI<\/a><br \/>\n\u3053\u3061\u3089\u306e\u30b5\u30a4\u30c8\u3067\u306frc.conf\u306b\u8d77\u52d5\u30aa\u30d7\u30b7\u30e7\u30f3\u3092\u66f8\u3044\u3066uwsgi\u3092\u8d77\u52d5\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u4e0a\u306e\u8aac\u660e\u3067\u306fini\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u308a\u307e\u3057\u305f\u304c\u3059\u3079\u3066\u5f15\u6570\u3067\u6e21\u3059\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u672c\u7684\u306a\u3068\u3053\u308d\u306f\u52d5\u304b\u305b\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u306e\u3067\u6b21\u306fnginx\u3068uWSGI\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3001\u8a2d\u5b9a\u3092\u884c\u3063\u3066\u5916\u304b\u3089\u898b\u3048\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002 \u3053\u306e\u3042\u305f\u308a\u306f\u524d\u306bpython\u3092uWSGI\u7d4c\u7531\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u3057\u3088\u3046\u3068\u601d\u3063\u305f\u6642\u306b\u3001\u672c\u4f53\u3068\u3042\u307e\u308a\u95a2\u4fc2\u306a\u3044\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.ekesete.net\/log\/?p=6912\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,32,38,7],"tags":[],"class_list":["post-6912","post","type-post","status-publish","format-standard","hentry","category-django","category-freebsd","category-python","category-7"],"_links":{"self":[{"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=\/wp\/v2\/posts\/6912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6912"}],"version-history":[{"count":51,"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=\/wp\/v2\/posts\/6912\/revisions"}],"predecessor-version":[{"id":7180,"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=\/wp\/v2\/posts\/6912\/revisions\/7180"}],"wp:attachment":[{"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ekesete.net\/log\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}