{"id":227,"date":"2022-04-05T02:02:53","date_gmt":"2022-04-04T18:02:53","guid":{"rendered":"http:\/\/139.224.63.49\/?p=227"},"modified":"2022-04-05T02:02:53","modified_gmt":"2022-04-04T18:02:53","slug":"%e5%9c%a8apache2%e4%b8%8a%e9%83%a8%e7%bd%b2flask%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/iamnear.top\/?p=227","title":{"rendered":"\u5728apache2\u4e0a\u90e8\u7f72flask\u7a0b\u5e8f"},"content":{"rendered":"\n<p>\u6700\u8fd1\u5199\u4e86\u4e2aflask\u5c0f\u7684\u540e\u7aefapi\uff0c\u5411\u90e8\u7f72\u5230apache2\u4e0a\uff0c\u6ca1\u60f3\u5230\u5751\u8fd8\u633a\u591a\uff0c\u6298\u817e\u4e86\u534a\u5929\u3002<\/p>\n\n\n\n<p>\u6211\u7684\u573a\u666f\u662f\u5728xxx.com:80\u7aef\u53e3\u5df2\u7ecf\u8dd1\u4e86\u4e00\u4e2aphp\u7684\u7f51\u7ad9\uff0c\u73b0\u5728\u6211\u60f3\u5728xxx.com:6666\u90e8\u7f72\u4e00\u4e2aflask\u7684\u540e\u7aefapi<\/p>\n\n\n\n<p>\u9996\u5148\u9700\u8981\u5b89\u88c5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install apache2-dev<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u5b89\u88c5\u597d\u4e86\u4ee5\u540e\u624d\u80fd <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip3 install mod_wsgi<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u786e\u5b9a\u4f60flask\u7684python\u7248\u672c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt-get install libapache2-mod-wsgi #if you are using python2\napt-get remove libapache2-mod-wsgi-py3 #if you are using python3<\/code><\/pre>\n\n\n\n<p>\u5fc5\u8981\u4e00\u4e9b\u4e1c\u897f\u5b89\u88c5\u597d\u4e86\u4ee5\u540e\uff0c\u9700\u8981\u627e\u4e2a\u7f51\u7ad9\u7684\u8def\u5f84\uff0c\u6bd4\u5982\/var\/www\/xxx\u5427\uff0c\u5728\u5176\u4e2d\u653e\u5165flask\u7a0b\u5e8f\uff0c\u518d\u65b0\u5efa\u4e00\u4e2axxx.wsgi,\u5176\u4e2d\u5185\u5bb9\u4e3a(\u5047\u8bbeflask app\u6240\u5728\u7684\u6587\u4ef6\u540d\u4e3axxx_app.py,)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import sys\nsys.path.insert(0, '\/var\/www\/xxx')\nfrom xxx_app import app as application<\/code><\/pre>\n\n\n\n<p>\u7f51\u7ad9\u7684\u5185\u5bb9\u653e\u597d\u4ee5\u540e\uff0c\u5f00\u59cb\u914d\u7f6eapache2<\/p>\n\n\n\n<p>\u5728\/etc\/apache2\/sites-available\u4e2d\u521b\u5efa\u65b0\u7684\u6587\u4ef6xxx.conf,\u5185\u5bb9\u5927\u6982\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;VirtualHost *:6666>\n\tServerName xxx.com:6666\n\tWSGIDaemonProcess xxx threads=5 home=\/var\/www\/xxx\n    WSGIScriptAlias \/ \/var\/www\/xxx\/xxx.wsgi\n\tWSGIScriptReloading On\n\n    &lt;Directory \/var\/www\/xxx>\n        WSGIProcessGroup xxx\n        WSGIApplicationGroup %{GLOBAL}\n        Order deny,allow\n        Allow from all\n    &lt;\/Directory>\n\n\tErrorLog ${APACHE_LOG_DIR}\/xxx_error.log\n\tCustomLog ${APACHE_LOG_DIR}\/xxx_access.log combined\n&lt;\/VirtualHost><\/code><\/pre>\n\n\n\n<p>\u8fd8\u8981\u5728\/etc\/apache2\/ports.conf\u6587\u4ef6\u4e2d\u52a0\u5165\u4e00\u53e5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Listen 6666<\/code><\/pre>\n\n\n\n<p>\u7136\u540e\u6267\u884c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a2ensite xxx\nservice apache2 restart<\/code><\/pre>\n\n\n\n<p>\u5373\u53ef<\/p>\n\n\n\n<p>\u4ee5\u4e0a\u5185\u5bb9\u57fa\u4e8e\u56de\u5fc6\uff0c\u6240\u4ee5\u4e0d\u4e00\u5b9a\u5bf9\uff0c\u4ec5\u4f9b\u53c2\u8003<\/p>\n\n\n\n<p>\u53c2\u8003\u7684\u4e00\u4e9b\u8d44\u6599\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><a href=\"http:\/\/www.pythondoc.com\/flask\/deploying\/mod_wsgi.html\">http:\/\/www.pythondoc.com\/flask\/deploying\/mod_wsgi.html<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/modwsgi.readthedocs.io\/en\/latest\/configuration-directives\/WSGIDaemonProcess.html\">https:\/\/modwsgi.readthedocs.io\/en\/latest\/configuration-directives\/WSGIDaemonProcess.html<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/33320889\/invalid-command-wsgidaemonprocess-deploy-django-application-on-centos-6-7\">https:\/\/stackoverflow.com\/questions\/33320889\/invalid-command-wsgidaemonprocess-deploy-django-application-on-centos-6-7<\/a><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-wp-embed is-provider-\u7984\u8def\u901a wp-block-embed-\u7984\u8def\u901a\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.lulutong.net.cn\/?p=61\n<\/div><\/figure>\n\n\n\n<p><a href=\"https:\/\/blog.csdn.net\/anchui6644\/article\/details\/101125644\">https:\/\/blog.csdn.net\/anchui6644\/article\/details\/101125644<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u5199\u4e86\u4e2aflask\u5c0f\u7684\u540e\u7aefapi\uff0c\u5411\u90e8\u7f72\u5230apache2\u4e0a\uff0c\u6ca1\u60f3\u5230\u5751\u8fd8\u633a\u591a\uff0c\u6298\u817e\u4e86\u534a\u5929\u3002 \u6211\u7684\u573a\u666f&hellip; <a href=\"http:\/\/iamnear.top\/?p=227\" class=\"more-link read-more\" rel=\"bookmark\">\u7ee7\u7eed\u9605\u8bfb <span class=\"screen-reader-text\">\u5728apache2\u4e0a\u90e8\u7f72flask\u7a0b\u5e8f<\/span><i class=\"fa fa-arrow-right\"><\/i><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-227","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-uncategorized","7":"h-entry","9":"h-as-article"},"_links":{"self":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=227"}],"version-history":[{"count":1,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions"}],"predecessor-version":[{"id":228,"href":"http:\/\/iamnear.top\/index.php?rest_route=\/wp\/v2\/posts\/227\/revisions\/228"}],"wp:attachment":[{"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=227"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/iamnear.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}