{"id":1055,"date":"2014-01-07T20:05:47","date_gmt":"2014-01-07T12:05:47","guid":{"rendered":"http:\/\/blog.dayandcarrot.net\/?p=1055"},"modified":"2014-01-07T20:05:47","modified_gmt":"2014-01-07T12:05:47","slug":"ubuntu%e4%b8%8b%e5%88%9b%e5%bb%badjango%e9%a1%b9%e7%9b%ae-%e4%bd%bf%e7%94%a8apache2%e7%9a%84mod-wsgi","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=1055","title":{"rendered":"Ubuntu\u4e0b\u521b\u5efaDjango\u9879\u76ee\u2014\u2014\u4f7f\u7528Apache2\u7684mod-wsgi"},"content":{"rendered":"<p>\u8bb0\u5f55\u672c\u4eba\u5728\u81ea\u5df1\u7684XEN VPS\u4e0a\u7528Apache2\u8dd1Django\u9879\u76ee\u7684\u914d\u7f6e\u8fc7\u7a0b<br \/>\n<a href=\"http:\/\/blog.dayandcarrot.net\/?attachment_id=1056\" rel=\"attachment wp-att-1056\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1056\" alt=\"QQ\u622a\u56fe20140107195633\" src=\"http:\/\/orz.dayandcarrot.net\/wordpress\/wp-content\/uploads\/2014\/01\/QQ\u622a\u56fe20140107195633.jpg\" width=\"937\" height=\"231\" \/><\/a>===============================================<br \/>\n\u6211\u7684\u865a\u62df\u4e3b\u673a\uff1a<br \/>\nUbuntu12.04 + Apache 2.2 + python2.7 + Django1.6.1(\u4f7f\u7528pip\u5b89\u88c5\u7684)<br \/>\n+ blablabla<br \/>\n===============================================<br \/>\n\u53c2\u8003\u6587\u6863\uff1a<br \/>\n<a href=\"https:\/\/docs.djangoproject.com\/en\/1.6\/howto\/deployment\/wsgi\/modwsgi\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.djangoproject.com\/en\/1.6\/howto\/deployment\/wsgi\/modwsgi\/<\/a><br \/>\n<a href=\"http:\/\/www.cnblogs.com\/zhengyun_ustc\/archive\/2009\/08\/11\/wsgi.html\">http:\/\/www.cnblogs.com\/zhengyun_ustc\/archive\/2009\/08\/11\/wsgi.html<\/a><br \/>\n<a href=\"http:\/\/wiki.ubuntu.org.cn\/Apache%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA%E6%8C%87%E5%8D%97\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/wiki.ubuntu.org.cn\/Apache%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA%E6%8C%87%E5%8D%97<\/a><br \/>\n<a href=\"https:\/\/www.digitalocean.com\/community\/articles\/installing-mod_wsgi-on-ubuntu-12-04\">https:\/\/www.digitalocean.com\/community\/articles\/installing-mod_wsgi-on-ubuntu-12-04<\/a><br \/>\n================================================<br \/>\n\u9996\u5148\u53c2\u8003\u6559\u7a0b\uff0c\u5b89\u88c5mod_wsgi<br \/>\n\u524d\u7f6e\u6761\u4ef6\uff1a<\/p>\n<pre class=\"toolbar-overlay:false lang:sh decode:true\">sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert<\/pre>\n<p>\u5b89\u88c5mod_wsgi (\u611f\u8c22ubuntu\u81ea\u5df1\u5e26\u4e86\u8fd9\u4e2a\u5b89\u88c5\u5305)<\/p>\n<pre class=\"toolbar:2 lang:sh decode:true\">sudo aptitude install libapache2-mod-wsgi<\/pre>\n<p>\u641e\u5b9a\u4e4b\u540e\u91cd\u542fapache<\/p>\n<pre class=\"toolbar:2 lang:sh decode:true\">sudo service apache2 restart<\/pre>\n<p>================================================<br \/>\n\u7b2c\u4e8c\u6b65\uff0c\u662f\u627e\u4e00\u4e2a\u5730\u65b9\uff0c\u81ea\u5df1\u65b0\u5efa\u4e00\u4e2aDjango\u9879\u76ee\uff0c\u6bd4\u5982\u6211\u7684\u9879\u76ee\u4f4d\u7f6e\u5728<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">\/media\/static\/django-proj\/priv_map<\/pre>\n<p>\u7136\u540e\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u6bd4\u5982\u6211\u7684\u6587\u4ef6\u5939\u53ebapache\uff0c\u6765\u5b58\u653ewsgi\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre class=\"toolbar:1 lang:python decode:true\" title=\"django.wsgi\">import os, sys\nsys.path.append('\/media\/static\/django-proj\/priv_map')\nos.environ['DJANGO_SETTINGS_MODULE'] = 'priv_map.settings'\nimport django.core.handlers.wsgi\napplication = django.core.handlers.wsgi.WSGIHandler()<\/pre>\n<p>\u4e0a\u9762\u7684\u914d\u7f6e\u5c31\u81ea\u5df1\u770b\u5566\uff0c\u6211\u7684django\u9879\u76ee\u540d\u5b57\u662f\u53ebpriv_map\u6765\u7740\u7684<br \/>\n\u7136\u540e\u63a5\u7740\u4e0b\u4e00\u6b65\uff0c\u9700\u8981\u5728apache\u7684\u914d\u7f6e\u76ee\u5f55\u4e2d\u5efa\u7acb\u4e00\u4e2a\u865a\u62df\u4e3b\u673a\uff0c\u8fd9\u6837\u5f53\u8f93\u5165\u7f51\u5740\u65f6\u80fd\u591f\u6839\u636e\u5185\u5bb9\u8f6c\u5411\u5230\u6211\u4eec\u7684django\u7a0b\u5e8f\u3002\u5f53\u7136\u4f60\u4e5f\u53ef\u4ee5\u4e0d\u65b0\u5efa\u865a\u62df\u4e3b\u673a\uff0c\u76f4\u63a5\u4fee\u6539default\u914d\u7f6e\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6211\u6ca1\u6709\u8bd5\u8fc7\uff0c\u4e0d\u8fc7\u80af\u5b9a\u662f\u53ef\u884c\u7684\uff01\u53c2\u8003\u6587\u732e\u4e2d\u6709\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u505a\u7684\u3002<br \/>\n\u627e\u5230\u4f60\u7684Apache\u914d\u7f6e\u76ee\u5f55\uff1a<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">\/etc\/apache2\/sites-available<\/pre>\n<p>\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\uff0c\u81ea\u5b9a\u4e49\u547d\u540d\uff0c\u53cd\u6b63\u7b49\u4e0b\u8981\u7528\u547d\u4ee4\u884c\u6765\u542f\u7528\u7684<br \/>\n\u6211\u7684\u8bbf\u95ee\u7684\u7ad9\u70b9\u662fa.dayandcarrot.net<\/p>\n<pre class=\"toolbar-overlay:false lang:apache decode:true\" title=\"a.dayandcarrot.net\">&lt;VirtualHost *:80&gt;\n    ServerName a.dayandcarrot.net\n    ServerAlias a.dayandcarrot.net\n    DocumentRoot \/media\/static\/django-proj\/priv_map\n    WSGIScriptAlias \/ \/media\/static\/django-proj\/priv_map\/apache\/django.wsgi\n    Alias \/static \/media\/static\/django-proj\/static\n    &lt;Location \"\/static\"&gt;\n            SetHandler None\n    &lt;\/Location&gt;\n    &lt;Directory \"\/media\/static\/django-proj\/static\"&gt;\n       Order Deny,Allow\n       Allow from all\n    &lt;\/Directory&gt;\n    &lt;Directory \"\/media\/static\/django-proj\/priv_map\/apache\"&gt;\n       Order Deny,Allow\n       Allow from all\n    &lt;\/Directory&gt;\n&lt;\/VirtualHost&gt;<\/pre>\n<p>\u5176\u4e2d\u6709django\u7684ststic\u76ee\u5f55\u914d\u7f6e\u597d\u4e86\uff0c\u9700\u8981\u53e6\u52a0media\u76ee\u5f55\u7684\u8bdd\uff0c\u7167\u846b\u82a6\u753b\u74e2\u5c31\u884c\u5427\u3002<br \/>\n\u4fdd\u5b58\u597d\u8fd9\u4e2a\u6587\u4ef6\u3002<br \/>\n\u7136\u540e\u542f\u7528\u8fd9\u4e2a\u865a\u62df\u4e3b\u673a\uff1a<\/p>\n<pre class=\"toolbar:2 lang:sh decode:true\">a2ensite a.dayandcarrot.net<\/pre>\n<p>\u540e\u9762\u7684a.dayandcarrot.net\u662f\u4f60\u521a\u624d\u65b0\u5efa\u7684\u6587\u4ef6\u7684\u540d\u5b57.<br \/>\n\u7136\u540eapache\u91cd\u65b0\u52a0\u8f7d\u4e0b<\/p>\n<pre class=\"toolbar:2 lang:sh decode:true\">service apache2 reload<\/pre>\n<p>\u5e94\u8be5\u5c31\u641e\u5b9a\u5566\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bb0\u5f55\u672c\u4eba\u5728\u81ea\u5df1\u7684XEN VPS\u4e0a\u7528Apache2\u8dd1Django\u9879\u76ee\u7684\u914d\u7f6e\u8fc7\u7a0b =============================================== \u6211\u7684\u865a\u62df\u4e3b\u673a\uff1a Ubuntu12.04 + Apache 2.2 + python2.7 + Django1.6.1(\u4f7f\u7528pip\u5b89\u88c5\u7684) + blablabla =============================================== \u53c2\u8003\u6587\u6863\uff1a https:\/\/docs.djangoproject.com\/en\/1.6\/howto\/deployment\/wsgi\/modwsgi\/ http:\/\/www.cnblogs.com\/zhengyun_ustc\/archive\/2009\/08\/11\/wsgi.html http:\/\/wiki.ubuntu.org.cn\/Apache%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA%E6%8C%87%E5%8D%97 https:\/\/www.digitalocean.com\/community\/articles\/installing-mod_wsgi-on-ubuntu-12-04 ================================================ \u9996\u5148\u53c2\u8003\u6559\u7a0b\uff0c\u5b89\u88c5mod_wsgi \u524d\u7f6e\u6761\u4ef6\uff1a sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert \u5b89\u88c5mod_wsgi (\u611f\u8c22ubuntu\u81ea\u5df1\u5e26\u4e86\u8fd9\u4e2a\u5b89\u88c5\u5305) sudo aptitude install libapache2-mod-wsgi \u641e\u5b9a\u4e4b\u540e\u91cd\u542fapache sudo service apache2 restart ================================================ \u7b2c\u4e8c\u6b65\uff0c\u662f\u627e\u4e00\u4e2a\u5730\u65b9\uff0c\u81ea\u5df1\u65b0\u5efa\u4e00\u4e2aDjango\u9879\u76ee\uff0c\u6bd4\u5982\u6211\u7684\u9879\u76ee\u4f4d\u7f6e\u5728 \/media\/static\/django-proj\/priv_map \u7136\u540e\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u6bd4\u5982\u6211\u7684\u6587\u4ef6\u5939\u53ebapache\uff0c\u6765\u5b58\u653ewsgi\u7684\u914d\u7f6e\u6587\u4ef6 import os, sys sys.path.append(&#8216;\/media\/static\/django-proj\/priv_map&#8217;) os.environ[&#8216;DJANGO_SETTINGS_MODULE&#8217;] = &#8216;priv_map.settings&#8217; import [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[21,38,89,114],"class_list":["post-1055","post","type-post","status-publish","format-standard","hentry","category-technical","tag-apache","tag-django","tag-python","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1055","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1055"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/1055\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1055"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1055"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1055"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}