{"id":436,"date":"2016-12-20T20:20:42","date_gmt":"2016-12-20T12:20:42","guid":{"rendered":"https:\/\/yyshell.com\/?p=436"},"modified":"2016-12-21T11:18:18","modified_gmt":"2016-12-21T03:18:18","slug":"centos7%e4%b8%8b%e7%94%a8apache-mod_proxy_uwsgi%e6%a8%a1%e5%9d%97%e6%90%ad%e5%bb%bauwsgi%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/yyshell.com\/?p=436","title":{"rendered":"CentOS7\u4e0b\u7528Apache mod_proxy_uwsgi\u6a21\u5757\u642d\u5efauwsgi\u5e94\u7528"},"content":{"rendered":"<p>\u4e4b\u524d\u6211\u4eec\u63d0\u5230\uff0c\u901a\u8fc7nginx+uwsgi\u642d\u5efauwsgi\u5e94\u7528\u7684<a href=\"https:\/\/yyshell.com\/?p=416\">\u6559\u7a0b<\/a>\uff0cnginx\u63d0\u4f9b\u4e86\u539f\u751f\u7684uwsgi\u534f\u8bae\u7684\u652f\u6301\uff0c\u8fd9\u662f\u76ee\u524d\u7684\u9ec4\u91d1\u7ec4\u5408\uff1b\u4f46\u662f\u6709\u65f6\u5019\uff0c\u6211\u4eec\u9700\u8981Apache\u642d\u5efa\u8fd9\u7c7b\u5e94\u7528\uff0c\u8fd9\u65f6\u5019\u5c31\u9700\u8981mod_proxy_uwsgi\u6a21\u5757\u4e86\uff0c\u8fd9\u4e5f\u662f\u76ee\u524d\u5b98\u65b9\u63a8\u8350\u7684Apache\u8dd1uwsgi\u7684\u65b9\u5f0f\u3002<\/p>\n<p>\u6211\u4eec\u7684\u73af\u5883\u4e3a\u4e00\u53f0CentOS7\u670d\u52a1\u5668\uff0cIP\uff1a192.168.1.200\uff0chostname\uff1acentos\uff0c<\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5epel\u4ed3\u5e93\u3002<\/p>\n<pre class=\"lang:sh decode:true \">yum install epel-release<\/pre>\n<p>\u5b89\u88c5\u5fc5\u8981\u7684\u7ec4\u4ef6\uff1a<\/p>\n<pre class=\"lang:sh decode:true \">yum install mod_proxy_uwsgi uwsgi-plugin-python<\/pre>\n<p>\u4ee5\u4e0a\u4e24\u4e2a\u7ec4\u4ef6\u4f1a\u56e0\u4e3a\u4f9d\u8d56\uff0c\u628ahttpd\u548cuwsgi\u5b89\u88c5\u4e0a\u53bb\uff0c\u6240\u4ee5\u5c31\u4e0d\u7528\u5355\u72ec\u5b89\u88c5\u4e86\u3002<\/p>\n<p>\u628a\u76f8\u5173\u670d\u52a1\u542f\u52a8\uff0c\u5e76\u8bbe\u7f6e\u4e3a\u81ea\u542f\u52a8<\/p>\n<pre class=\"lang:sh decode:true \">systemctl enable uwsgi.service\r\nsystemctl enable httpd.service\r\nsystemctl start uwsgi.service\r\nsystemctl start httpd.service<\/pre>\n<p>\u6211\u4eec\u4ee5flask\u7a0b\u5e8f\u4e3a\u4f8b\uff0c\u8fdb\u884c\u6d4b\u8bd5\uff0c\u5148\u5b89\u88c5flask\u3002<\/p>\n<pre class=\"lang:sh decode:true \">yum install python-flask<\/pre>\n<p>\u521b\u5efa\u6587\u6863\u76ee\u5f55\uff1a<\/p>\n<pre class=\"lang:sh decode:true \">mkdir \/srv\/demo<\/pre>\n<p>\u5728\u4e0a\u9762\u7684\u76ee\u5f55\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2aflask\u7a0b\u5e8ftest.py:<\/p>\n<pre class=\"lang:python decode:true  \">from flask import Flask\r\napp = Flask(__name__)\r\n\r\n@app.route(\"\/\")\r\ndef hello():\r\n    return \"&lt;h1 style='color:blue'&gt;This is demo site!&lt;\/h1&gt;\"\r\n\r\nif __name__ == \"__main__\":\r\n    app.run(host='0.0.0.0')<\/pre>\n<p>\u6539\u4e0b\u6587\u4ef6\u6743\u9650\uff1a<\/p>\n<pre class=\"lang:sh decode:true\">chown -R uwsgi:uwsgi \/srv\/demo\r\nsemanage fcontext -a -t httpd_sys_rw_content_t \"\/srv\/demo(\/.*)?\"\r\nrestorecon -Rv \/srv\/demo\/<\/pre>\n<p>Apache\u542f\u7528\u6a21\u5757\uff1a<br \/>\nvim \/etc\/httpd\/conf.modules.d\/00-uwsgi.conf<\/p>\n<pre class=\"lang:apache decode:true \">LoadModule proxy_uwsgi_module modules\/mod_proxy_uwsgi.so<\/pre>\n<p>\u914d\u7f6e\u4e0buwsgi\uff1a<br \/>\nvim \/etc\/uwsgi.d\/demo.ini<\/p>\n<pre class=\"lang:ini decode:true \">[uwsgi]\r\nplugin = python\r\nbase = \/srv\/demo\r\nchdir = \/srv\/demo\r\nmodule = test\r\npythonpath = %(base)\r\nsocket = %(base)\/%n.sock\r\nchmod-socket = 666\r\ncallable = app\r\nlogto = \/var\/log\/%n.log<\/pre>\n<p>\u522b\u5fd8\u8bb0\u66f4\u6539\u4e0b\u7528\u6237\u5c5e\u4e3b\uff1a<\/p>\n<pre class=\"lang:sh decode:true \">chown uwsgi:uwsgi demo.ini<\/pre>\n<p>\u521b\u5efa\u4e0buwsgi\u65e5\u5fd7\u6587\u4ef6\uff1a<\/p>\n<pre class=\"lang:sh decode:true \">touch \/var\/log\/demo.log\r\nchown uwsgi:uwsgi \/var\/log\/demo.log<\/pre>\n<p>\u6700\u540e\u521b\u5efa\u4e0bApache\u6b63\u5f0f\u7684\u6587\u6863\u76ee\u5f55\u914d\u7f6e\u6587\u4ef6\uff1a<br \/>\nvim \/etc\/httpd\/conf.d\/uwsgi.conf<\/p>\n<pre class=\"lang:apache decode:true\">ProxyPass \/ unix:\/srv\/demo\/demo.sock|uwsgi:\/\/demo\/<\/pre>\n<p>\u6ce8\u610f\uff0c\u540e\u9762\u7684uwsgi:\/\/demo\/\u662f\u4e3a\u4e86\u533a\u5206\u591a\u4e2auwsgi\u7528\u7684\uff0c\u591a\u4e2a\u5e94\u7528\u9700\u8981\u7528\u4e0d\u540c\u7684\u540d\u79f0\u533a\u5206\uff0c\u4ec5\u4ec5\u91c7\u7528\u4e0d\u540c\u7684unix socket\u662f\u65e0\u6cd5\u5de5\u4f5c\u7684\u3002\u53e6\u5916\uff0c\u901a\u8fc7\u6dfb\u52a0\u865a\u62df\u4e3b\u673a\uff0c\u53ef\u4ee5\u91c7\u7528\u4e0d\u540c\u7684\u57df\u540d\uff0c\u6216\u8005\u901a\u8fc7\u4e0d\u540c\u7684\u7aef\u53e3\u53f7\u6765\u8ba9\u591a\u4e2auwsgi\u5e94\u7528\u4e00\u8d77\u5de5\u4f5c\u3002<\/p>\n<p>\u6700\u540e\u91cd\u542f\u4e0b\u670d\u52a1\uff1a<\/p>\n<pre class=\"lang:sh decode:true \">systemctl restart uwsgi.service\r\nsystemctl restart httpd.service<\/pre>\n<p>\u8bbf\u95eehttp:\/\/192.168.1.200\/ \uff0c\u6b64\u65f6\u5e94\u8be5\u80fd\u5de5\u4f5c\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u6211\u4eec\u63d0\u5230\uff0c\u901a\u8fc7nginx+uwsgi\u642d\u5efauwsgi\u5e94\u7528\u7684\u6559\u7a0b\uff0cnginx\u63d0\u4f9b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8],"tags":[28,37,74,66],"class_list":["post-436","post","type-post","status-publish","format-standard","hentry","category-linux","category-web","tag-apache","tag-centos7","tag-mod_proxy_uwsgi","tag-uwsgi"],"_links":{"self":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=436"}],"version-history":[{"count":2,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/436\/revisions"}],"predecessor-version":[{"id":438,"href":"https:\/\/yyshell.com\/index.php?rest_route=\/wp\/v2\/posts\/436\/revisions\/438"}],"wp:attachment":[{"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yyshell.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}