{"id":9002,"date":"2024-03-23T21:35:03","date_gmt":"2024-03-23T13:35:03","guid":{"rendered":"https:\/\/egonlin.com\/?p=9002"},"modified":"2024-05-28T23:11:27","modified_gmt":"2024-05-28T15:11:27","slug":"%e4%b8%80%e3%80%81web%e5%ba%94%e7%94%a8%e5%b1%82-lnmp","status":"publish","type":"post","link":"https:\/\/egonlin.com\/?p=9002","title":{"rendered":"\u4e8c\u3001web\u5e94\u7528\u5c42-lnmp"},"content":{"rendered":"<h1>\u4e00\u3001\u672c\u7ae0\u4e3b\u9898<\/h1>\n<p>lnmp\/lamp<\/p>\n<p>\u90e8\u7f72php\u8bed\u8a00\u7f16\u5199\u7684web\u5e94\u7528\u7a0b\u5e8f<br \/>\n\u90e8\u7f72python\u8bed\u8a00\u7f16\u5199\u7684web\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u5f3a\u8c03\uff1a<br \/>\n\u4e86\u89e3\u600e\u4e48\u90e8\u7f72\u65f6\u6700\u6700\u6700\u7b80\u5355\u7684\u4e00\u4e2a\u73af\u8282\uff0c\u975e\u5e38\u975e\u5e38\u7684low<br \/>\n\u4f60\u8981\u60f3\u8fbe\u5230\u901a\u900f\u7684\u6548\u679c\uff0c\u65e0\u8bba\u4ec0\u4e48\u5e94\u7528\u7ed9\u4f60\uff0c\u4f60\u7785\u4e00\u773c\u5c31\u77e5\u9053\u67b6\u6784\u601d\u8def\uff0c\u4efb\u4f55\u73af\u8282\u51fa\u4e86\u95ee\u9898\u90fd\u80fd\u591f\u5b9a\u4f4d\u5230\u95ee\u9898\u5728\u54ea\u91cc<\/p>\n<p>\u5173\u952e\u5c31\u5728\u4e8e\uff1a\u641e\u6e05\u695a\u4e0a\u6e38\u4e0e\u4e0b\u6e38\u8d70\u7684\u662f\u4ec0\u4e48\u534f\u8bae\uff0c\u4e0a\u6e38\u662f\u600e\u4e48\u505a\u7684\uff0c\u4e0b\u6e38\u662f\u600e\u4e48\u505a\u7684\uff0c\u5982\u6b64\uff0c\u4fbf\u53ef\u4ee5\u5728\u81ea\u5df1\u7684\u8111\u5b50\u91cc\u751f\u6210\u4e00\u6574\u6761\u94fe\u8def\u6216\u8005\u8bf4\u6d41\u6c34\u7ebf\uff0c\u4e00\u4e2a\u6570\u636e\u5305\u5c31\u6cbf\u7740\u8fd9\u4e2a\u6d41\u6c34\u7ebf\u4e00\u4e2a\u5c0f\u8282\u70b9\u4e00\u4e2a\u5c0f\u59d0\u70b9\u7684\u8d70\u4e0b\u53bb\uff0c\u4f46\u51e1\u67d0\u4e2a\u5c0f\u8282\u70b9\u4f60\u662f\u6a21\u7cca\u7684\uff0c\u4f60\u90fd\u5e94\u8be5\u82b1\u7cbe\u529b\u53bb\u641e\u5b9a\u5b83\uff0c\u5426\u5219\u5c31\u662f\u6ca1\u5b66\u4f1a\uff0c\u5343\u4e07\u4e0d\u8981\u5929\u771f\u7684\u4ee5\u4e3a\uff0c\u6211\u80fd\u90e8\u7f72\u8d77\u6765\uff0c\u80fd\u8dd1\u8d77\u6765\uff0c\u5c31\u662f\u5b66\u4f1a\u4e86\uff0c\u90a3\u6837\u5b50\u771f\u7684\u5f88\u4f4e\u7aef\uff0c\u867d\u7136\u53ef\u80fd\u4e5f\u5e76\u4e0d\u5f71\u54cd\u4f60\u9762\u8bd5\u751a\u81f3\u62ff\u9ad8\u85aa\uff0c\u4f46\u540e\u52b2\u4e0d\u8db3\u662f\u80af\u5b9a\u7684\u3002<\/p>\n<h1>\u4e8c\u3001\u5148\u8bf4\u91cd\u8981\u7ed3\u8bba<\/h1>\n<p>\u4e0b\u8ff0\u91cd\u8981\u7ed3\u8bba\u5747\u6765\u81ea\u4e8e\u8be5\u6587\u7ae0\uff1a<a href=\"https:\/\/egonlin.com\/?p=9138\">https:\/\/egonlin.com\/?p=9138<\/a><br \/>\n\u4e00\u5b9a\u8981\u597d\u597d\u770b\u770b\u4e0a\u9762\u8fd9\u7bc7\u6587\u7ae0\uff0c\u8be6\u89e3\u4ecb\u7ecd\u4e86\uff1acgi\u3001fastcgi\u3001php-fpm\uff0c\u4ee5\u53capython\u4f53\u7cfb\u91cc\u7684\uff08wsgi\u3001uwsgi\u3001agi\uff09<br \/>\n\u7684\u6f14\u53d8\u5386\u53f2\uff0c\u5173\u7cfb\u4e0e\u533a\u522b<\/p>\n<h2>2.1 python\u4f53\u7cfb\u4e0ephp\u4f53\u7cfb\u603b\u56fe<\/h2>\n<p>\u4e0b\u56fe\u753b\u7684\u662fweb\u5c42\u670d\u52a1\u5668\u4e0a\u7684\u670d\u52a1\u94fe\u8def\uff0c\u6700\u5de6\u4fa7\u7684HTTP\u8bf7\u6c42\u53ef\u4ee5\u662f\u7528\u6237\u53d1\u8d77\u7684\uff0c\u4e5f\u53ef\u4ee5\u662f\u4e0a\u6e38\u7684\u8d1f\u8f7d\u5747\u8861\u5668<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/\u5fae\u4fe1\u56fe\u7247_20240528230905.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" class=\"alignnone size-full wp-image-10999\" data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/\u5fae\u4fe1\u56fe\u7247_20240528230905.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" width=\"1458\" height=\"789\"  sizes=\"(max-width: 1458px) 100vw, 1458px\" \/><\/div><br \/>\n\u4f5c\u8005\u81ea\u5df1\u7559\u5b58\u4f5c\u56fe\u5730\u5740\uff1a<a href=\"https:\/\/www.processon.com\/diagraming\/58883630e4b049e795e80bcf\">https:\/\/www.processon.com\/diagraming\/58883630e4b049e795e80bcf<\/a><\/p>\n<h2>2.2 nginx\u914d\u7f6e\u8f6c\u53d1\u5230\u4e0d\u540c\u534f\u8bae\u7684\u6307\u4ee4<\/h2>\n<p>nginx\u7528\u4e8e\u5c06\u8bf7\u6c42\u8f6c\u7ed9\u5176\u4ed6\u8fdb\u7a0b\u7684\u5185\u7f6e\u6307\u4ee4\uff08\u4e0d\u9700\u8981\u4e3anginx\u989d\u5916\u5b89\u88c5\u5305\uff0c\u9ed8\u8ba4\u652f\u6301\uff09<\/p>\n<pre><code>proxy_pass\uff1ahttp\u534f\u8bae\r\nfastcgi_pass\uff1afastcgi\u534f\u8bae\r\nuwsgi_pass\uff1auwsgi\u534f\u8bae\r\n\r\n\u5f3a\u8c03\uff1a\r\n1\u3001uwsgi\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6uwsgi.ini\r\nhttp = :8080 \u4ee3\u8868uwsgi\u670d\u52a1\u76d1\u542chttp\u534f\u8bae\u7aef\u53e3\r\nsocket = :8080 \u4ee3\u8868uwsgi\u670d\u52a1\u76d1\u542cuwsgi\u534f\u8bae\u7684\u7aef\u53e3\r\n\r\n\u9488\u5bf9\u524d\u8005\uff0c\u5728nginx\u91cc\u9700\u8981\u7528proxy_pass\u8f6c\u53d1\r\n\u9488\u5bf9\u540e\u8005\uff0c\u5728nginx\u91cc\u9700\u8981\u7528uwsgi_pass\u8f6c\u53d1\r\n\r\n2\u3001uwsgi\u534f\u8bae\u80af\u5b9ahttp\u534f\u8bae\u66f4\u5feb\r\n\r\n3\u3001\u9488\u5bf9python\u4f53\u7cfb-asgi\u534f\u8bae\uff0cnginx\u914d\u7f6e\u8f6c\u53d1\u7ed9daphne\u670d\u52a1\uff0c\u7528\u7684\u5c31\u662fproxy_pass,\r\n\u56e0\u4e3adaphne\u652f\u6301\u7684http\u534f\u8bae\uff0c\u6ca1\u6709asgi_pass\u8fd9\u79cd\u4e1c\u897f<\/code><\/pre>\n<h2>2.3 web\u5c42\u90e8\u7f72python\u7a0b\u5e8f<\/h2>\n<p>uwsgi\u670d\u52a1\u7684\u914d\u7f6e\u6587\u4ef6uwsgi.ini\u53ef\u4ee5\u914d\u7f6e\u5f00\u542fhttp\u534f\u8bae\u4e0euwsgi\u534f\u8bae<\/p>\n<pre><code># 1\u3001\u76d1\u542chttp\u534f\u8bae\r\nhttp = :8081\r\n\r\n# 2\u3001\u76d1\u542cuwsgi\u534f\u8bae\r\nsocket = :8082<\/code><\/pre>\n<p>\u4e24\u6761\u914d\u7f6e\u53ef\u4ee5\u540c\u65f6\u51fa\u73b0\u5728uwsgi.ini\u4e2d\uff0c\u53ea\u8981\u7aef\u53e3\u4e0d\u51b2\u7a81\u5c31\u884c\uff0c\u4f46\u901a\u5e38\u60c5\u51b5\u4e0b\u6211\u4eec\u53ea\u4f1a\u9009\u62e9\u5f00\u542f\u5176\u4e2d\u4e00\u79cd<\/p>\n<p>python\u4f53\u7cfb\uff1a<\/p>\n<ul>\n<li>1\u3001uwsgi.ini\u914d\u7f6e\u4e3ahttp=:8080\uff0c\u6b64\u65f6uwsgi\u670d\u52a1\u53ef\u4ee5\u5145\u5f53web\u670d\u52a1\u7528\uff0cuwsgi\u670d\u52a1\u5904\u7406\u7684\u5c31\u662fhttp\u534f\u8bae\n<pre><code>uwsgi\u670d\u52a1\u63a5\u6536http\u534f\u8bae\u8bf7\u6c42\uff0c\u7136\u540e\u5c01\u88c5\u6210wsgi\u534f\u8bae\u5f80\u540e\u9762\u7684\u5e94\u7528\u7a0b\u5e8f\u4f20<\/code><\/pre>\n<\/li>\n<li>2\u3001uwsgi.ini\u914d\u7f6e\u4e3asocket=:8080,\u4ee3\u8868\u7528uwsgi\u670d\u52a1\u5f53\u4e2d\u95f4\u4ef6\uff0c\u914d\u5408nginx\u4e00\u8d77\u4f7f\u7528\uff0cuwsgi\u4e0enginx\u4e4b\u95f4\u8d70\u7684\u662fuwsgi\u534f\u8bae\n<pre><code>1\u3001nginx\u670d\u52a1\u63a5\u53d7http\u534f\u8bae\u7684\u8bf7\u6c42\uff0c\u7136\u540e\u5c01\u88c5\u6210uwsgi\u534f\u8bae\u5f80\u540e\u9762\u7684\u4e2d\u95f4\u4ef6\u5373uwsgi\u670d\u52a1\u4f20\r\n2\u3001uwsgi\u670d\u52a1\u5c06\u8bf7\u6c42\u8fdb\u4e00\u6b65\u5904\u7406\u6210wsgi\u534f\u8bae\u5f80\u540e\u9762\u7684\u5e94\u7528\u7a0b\u5e8f\u4f20<\/code><\/pre>\n<\/li>\n<li>3\u3001\u540c\u65f6\u914d\u7f6e\u6709http=:8081\u3001socket=:8082\uff0c\u7aef\u53e3\u4e00\u5b9a\u4e0d\u80fd\u51b2\u7a81\u3002\u540c\u65f6\u5f00\u542f\u7684\u610f\u4e49\u4e0d\u5927\uff0c\u4e00\u822c\u90fd\u53ea\u5f00\u542f\u4e00\u79cd\u6765\u6ee1\u8db3\u4f60\u7684\u7279\u5b9a\u9700\u6c42<\/li>\n<\/ul>\n<h2>2.3 web\u5c42\u90e8\u7f72php\u7a0b\u5e8f<\/h2>\n<p>PHP-frm\u4e0d\u652f\u6301http\u534f\u8bae\uff0c\u4e0d\u80fd\u76f4\u63a5\u5145\u5f53web\u670d\u52a1\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff01<br \/>\nPHP-FPM \u672c\u8eab\u5e76\u4e0d\u76f4\u63a5\u652f\u6301 HTTP \u534f\u8bae\uff0c\u5b83\u4e3b\u8981\u4f7f\u7528\u7684\u662f FastCGI \u534f\u8bae\u3002\u8fd9\u610f\u5473\u7740PHP-FPM\u5e76\u4e0d\u80fd\u76f4\u63a5\u5bf9\u5916\u63d0\u4f9bhttp\u534f\u8bae\u7684\u670d\u52a1\u3002\u901a\u5e38\u5b83\u548c Nginx \u6216\u8005 Apache \u7b49 Web \u670d\u52a1\u5668\u914d\u5408\u6765\u4f7f\u7528\u3002<br \/>\nHTTP \u8bf7\u6c42\u6700\u5148\u7531 Web \u670d\u52a1\u5668\uff08\u5982 Nginx \u6216 Apache\uff09\u63a5\u6536\uff0c\u7136\u540e\u7531 Web \u670d\u52a1\u5668\u901a\u8fc7 FastCGI \u534f\u8bae\u4f20\u9012\u7ed9 PHP-FPM\u6765\u5904\u7406\uff0c<\/p>\n<p>\u603b\u7ed3\uff1anginx\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9php-fpm\uff0cphp-fpm\u8d1f\u8d23\u8c03\u7528php\u7a0b\u5e8f\uff0c\u6574\u4e2a\u8fc7\u7a0b\u6d89\u53ca\u4e09\u79cd\u7a0b\u5e8f\uff0cnginx\u3001php-fpm\u3001php\u7a0b\u5e8f\uff0c\u8fd9\u4e09\u8005\u4e4b\u95f4\u6570\u636e\u7684\u8f6c\u53d1\u5206\u522b\u8d70\u4ec0\u4e48\u534f\u8bae<\/p>\n<ul>\n<li>1\u3001Nginx\u548cPHP-FPM\u4e4b\u95f4\u7684\u901a\u4fe1\uff1a\u7528\u7684\u662fFastCGI\u534f\u8bae\u3002\u5f53Nginx\u6536\u5230\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u540e\uff0c\u5982\u679c\u8fd9\u4e2a\u8bf7\u6c42\u9700\u8981PHP\u8fdb\u884c\u5904\u7406\uff0cNginx\u5c31\u4f1a\u4f7f\u7528FastCGI\u534f\u8bae\uff0c\u5c06\u8bf7\u6c42\u8f6c\u53d1\u7ed9PHP-FPM\u8fdb\u884c\u5904\u7406\u3002<\/li>\n<li>2\u3001PHP-FPM\u548cPHP\u7a0b\u5e8f\u4e4b\u95f4\u7684\u901a\u901a\u4fe1\uff1a\u5b9e\u9645\u4e0a\u5e76\u6ca1\u6709\u4e00\u4e2a\u660e\u786e\u7684\u534f\u8bae\u3002PHP-FPM\u542f\u52a8\u65f6\uff0c\u4f1a\u52a0\u8f7dPHP\u89e3\u91ca\u5668\uff0c\u7136\u540e\u4fdd\u6301\u5728\u5185\u5b58\u4e2d\u3002\u5f53PHP-FPM\u6536\u5230\u4e00\u4e2a\u8bf7\u6c42\u65f6\uff0c\u5b83\u4f1a\u8c03\u7528\u5185\u5b58\u4e2d\u7684PHP\u89e3\u91ca\u5668\u6765\u5904\u7406\u8bf7\u6c42\uff0c\u5e76\u4f20\u9012\u7ed9\u89e3\u91ca\u5668\u6240\u9700\u7684\u6240\u6709\u73af\u5883\u53d8\u91cf\u548c\u8bf7\u6c42\u5185\u5bb9\u3002\u8fd9\u4e9b\u90fd\u662f\u5728\u672c\u5730\u8fdb\u884c\u7684\uff0c\u4e0d\u9700\u8981\u7f51\u7edc\u534f\u8bae\u3002<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711434346044.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711434346044.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/li>\n<\/ul>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711380255731.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711380255731.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/p>\n<p>Nginx \u4f5c\u4e3aweb\u670d\u52a1\uff0c\u65e0\u6cd5\u76f4\u63a5\u4e0e FastCGI \u7a0b\u5e8f\uff08\u4f8b\u5982php-fpm\uff09\u8fdb\u884c\u901a\u4fe1\uff0c\u9700\u8981\u542f\u7528ngx_http_fastcgi_module\u6a21\u5757\u8fdb\u884c\u4ee3\u7406\u914d\u7f6e\uff0c\u624d\u80fd\u5c06\u8bf7\u6c42\u53d1\u9001\u7ed9 FastCGI \u7a0b\u5e8f\uff08\u4f8b\u5982php-fpm\uff09\u3002<br \/>\n\u5176\u4e2d\uff0c\u5305\u62ec\u6211\u4eec\u719f\u77e5\u7684\u914d\u7f6e\u6307\u4ee4\uff1a<br \/>\nfastcgi_pass \u7528\u4e8e\u8bbe\u7f6e FastCGI \u670d\u52a1\u5668\u7684 IP \u5730\u5740\uff08TCT \u5957\u63a5\u5b57\uff09\u6216 UNIX \u5957\u63a5\u5b57\u3002<br \/>\nfastcgi_param \u8bbe\u7f6e\u4f20\u5165 FastCGI \u670d\u52a1\u5668\u7684\u53c2\u6570\u3002<br \/>\n\u63a5\u4e0b\u6765\u770b\u4e00\u4e0bfastcgi_pass\u8f6c\u53d1fastcgi\u534f\u8bae\u7684\u8bf7\u6c42\u8be5\u5982\u4f55\u914d\u7f6e<\/p>\n<pre><code># \u5b98\u7f51\uff1ahttps:\/\/www.php.net\/manual\/zh\/install.fpm.php\r\n# This is the origin nginx conf.\r\nlocation ~ \\.php$ {\r\n    try_files  $uri = 404;\r\n    fastcgi_pass  127.0.0.1:9000;\r\n    fastcgi_index  index.php;\r\n    include  fastcgi.conf;\r\n}\r\n\r\n# You can replace it by\r\nupstream php {\r\n    server  127.0.0.1:9000;\r\n    server  127.0.0.1:9001;\r\n    server  127.0.0.1:9002;\r\n    server  127.0.0.1:9003;\r\n}\r\n\r\nlocation ~ \\.php$ {\r\n    try_files  $uri = 404;\r\n    fastcgi_pass  php;\r\n    fastcgi_index  index.php;\r\n    include  fastcgi.conf;\r\n}<\/code><\/pre>\n<h1>\u4e09\u3001\u518d\u7b80\u8ff0\u6838\u5fc3\u53d1\u5c55\u53f2<\/h1>\n<h2>3.1 php\u4f53\u7cfb<\/h2>\n<p>php\u4f53\u7cfb\u76f8\u5173\uff1acgi\u3001FastCGI\u3001php-fpm<\/p>\n<pre><code>1\u3001\u5728\u4f20\u7edf\u7684 CGI \u6a21\u5f0f\u4e0b\uff0c\u6bcf\u6b21 HTTP \u8bf7\u6c42\u90fd\u9700\u8981 fork \u4e00\u4e2a\u65b0\u7684\u8fdb\u7a0b\u7528\u4e8e\u5904\u7406\uff0c\u8fdb\u7a0b\u7ed3\u675f\u540e\u5373\u91ca\u653e\u8d44\u6e90\u3002\r\n\u8fd9\u79cd\u65b9\u5f0f\u5728\u5904\u7406\u5927\u91cf\u5e76\u53d1\u8bf7\u6c42\u65f6\u4f1a\u5e26\u6765\u4e25\u91cd\u7684\u6027\u80fd\u95ee\u9898\u3002\r\n\r\n2\u3001FastCGI \u534f\u8bae\u662f CGI \u534f\u8bae\u7684\u4e00\u79cd\u53d8\u79cd\uff0c\u8bbe\u8ba1\u4e4b\u521d\u5c31\u662f\u4e3a\u4e86\u5f25\u8865 CGI \u534f\u8bae\u5728\u6301\u4e45\u8fde\u63a5\u548c\u6027\u80fd\u4e0a\u7684\u4e0d\u8db3\u3002 \r\n\u5219\u5141\u8bb8\u4e00\u4e2a\u957f\u671f\u8fd0\u884c\u7684\u8fdb\u7a0b\uff08\u6bd4\u5982 PHP-FPM\uff09\u6765\u5904\u7406\u591a\u4e2a HTTP \u8bf7\u6c42\uff0c\u8fd9\u5927\u5927\u63d0\u9ad8\u4e86\u5904\u7406\u6548\u7387\u3002\r\n\r\n3\u3001PHP-FPM \u662fFastCGI \u534f\u8bae\u7684\u5177\u4f53\u5b9e\u73b0\uff0c\u4ece\u540d\u5b57\u4e0a\u4e5f\u80fd\u770b\u51fa\u6765PHP-FPM \uff08PHP FastCGI Process Manager\uff09\uff0c\r\n\u5373php-fpm\u662f\u57fa\u4e8eFastCGI\u534f\u8bae\u7684\u8fdb\u7a0b\u7ba1\u7406\u5668<\/code><\/pre>\n<p>\u5305\u7684\u534f\u8bae\u5c01\u88c5\u4e0e\u8f6c\u53d1\u6d41\u7a0b\u5982\u4e0b<\/p>\n<pre><code>\u5fc5\u987b\u8981\u6709\u4e00\u4e2anginx\u4e00\u6837\u7684web\u670d\u52a1\u5b58\u5728\u624d\u884c\r\n\r\nnginx\u670d\u52a1---\uff08FastCGI\u534f\u8bae\uff09-------&gt; php-fpm\u670d\u52a1\uff08\u5185\u90e8\u8c03\u7528web\u5e94\u7528\uff09<\/code><\/pre>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711435118848.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711435118848.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/p>\n<h2>3.2 python\u4f53\u7cfb<\/h2>\n<p>python\u4f53\u7cfb\u76f8\u5173\uff1awsgi\u3001asgi\u3001uwsgi<\/p>\n<pre><code>1\u3001web\u670d\u52a1\u4e0eweb\u5e94\u7528\u4e4b\u95f4\u7684\u534f\u8bae\u53ef\u4ee5\u662fwsgi\u6216asgi\r\n2\u3001web\u670d\u52a1\u4e0e\u5176\u4ed6web\u670d\u52a1\u4e4b\u95f4\u7684\u534f\u8bae\u53ef\u4ee5\u662fhttp\u6216uwsgi\u534f\u8bae<\/code><\/pre>\n<p>\u5305\u7684\u534f\u8bae\u5c01\u88c5\u4e0e\u8f6c\u53d1\u6d41\u7a0b\u5982\u4e0b<br \/>\n<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711435176164.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711435176164.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/p>\n<h2>3.3 php\u4f53\u7cfb\u4e0epython\u4f53\u7cfb\u603b\u7ed3\u4e0e\u5bf9\u6bd4<\/h2>\n<p>\u76f8\u540c\u70b9\uff1a<br \/>\nuwsgi\u7a0b\u5e8f==============\u62c9\u8d77================python\u7684web\u5e94\u7528<br \/>\nphp-fpm\u7a0b\u5e8f============\u62c9\u8d77================php\u7684web\u5e94\u7528<\/p>\n<p>\u4e0d\u540c\u70b9\uff1a<br \/>\n1\u3001uwsgi\u7a0b\u5e8f\u53ef\u4ee5\u89e3\u6790uwsgi\u534f\u8bae\uff0c\u4e5f\u53ef\u4ee5\u89e3\u6790http\u534f\u8bae\uff0c\u6240\u4ee5uwsgi\u7a0b\u5e8f\u53ef\u4ee5\u542f\u52a8\u4e3a\u4e00\u4e2aweb\u670d\u52a1\u7528\uff0c\u5e76\u4e0d\u662f\u4e00\u5b9a\u9700\u8981\u642d\u914dnginx\uff0c\u867d\u7136\u901a\u5e38\u6211\u4eec\u5efa\u8bae\u642d\u914dnginx\u4e00\u8d77\u7528<br \/>\n2\u3001php-fpm\u7a0b\u5e8f\u542f\u52a8\u4e4b\u540e\uff0c\u53ea\u80fd\u89e3\u6790fastcgi\u534f\u8bae\uff0c\u4e0d\u652f\u6301http\u534f\u8bae\uff0c\u6240\u4ee5php-fpm\u542f\u52a8\u4e4b\u540e\u4e0d\u80fd\u4f5c\u4e3a\u4e00\u4e2aweb\u670d\u52a1\u7528\uff0c\u4e00\u5b9a\u8981\u642d\u914d\u50cfnginx\u4e00\u6837\u7684web\u670d\u52a1\u7528\u624d\u884c<\/p>\n<pre><code>\u867d\u7136uWSGI\u53ef\u4ee5\u76f4\u63a5\u63d0\u4f9bHTTP\u534f\u8bae\u7684\u7aef\u53e3\uff0c\u6240\u4ee5\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u7b80\u5355\u7684Web\u670d\u52a1\u5668\uff0c\u4f46\u5b9e\u9645\u4e0a\u5728\u5927\u591a\u6570\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\r\nuWSGI\u901a\u5e38\u8fd8\u662f\u4f1a\u642d\u914dNginx\u7b49Web\u670d\u52a1\u5668\u6765\u4f7f\u7528\uff0c\u4ee5\u4fbf\u5229\u7528Nginx\u7684\u9ad8\u6548\u9759\u6001\u6587\u4ef6\u5904\u7406\uff0c\u8d1f\u8f7d\u5747\u8861\u7b49\u7279\u6027\u3002\r\n\u81f3\u4e8ePHP-FPM\uff0c\u5b83\u5e76\u4e0d\u80fd\u76f4\u63a5\u4f5c\u4e3aWeb\u670d\u52a1\u5668\u3002PHP-FPM\u662f\u4e00\u4e2a\u8fdb\u7a0b\u7ba1\u7406\u5668\uff0c\u5b83\u7ef4\u62a4\u4e86\u4e00\u7ec4FastCGI\u8fdb\u7a0b\uff0c\r\n\u53ef\u4ee5\u5904\u7406PHP\u4ee3\u7801\u7684\u6267\u884c\u3002\r\n\r\n\u6240\u4ee5\uff0c\r\nuWSGI\u53ef\u4ee5\u63d0\u4f9bHTTP\u534f\u8bae\u7aef\u53e3\u76f4\u63a5\u5145\u5f53Web\u670d\u52a1\u5668\uff0c\u4f46PHP-FPM\u5e76\u4e0d\u80fd\u8fd9\u6837\u505a\uff0c\r\n\u5b83\u53ea\u662f\u4f5c\u4e3a\u5904\u7406PHP\u4ee3\u7801\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u800c\u975e\u5904\u7406HTTP\u8bf7\u6c42\u7684Web\u670d\u52a1\u5668\u3002<\/code><\/pre>\n<h1>\u56db\u3001lnmp-\u90e8\u7f72php<\/h1>\n<p>\u53ea\u6709\u4e00\u79cd\u65b9\u6848\uff0c\u5c31\u662f\u5fc5\u987b\u642d\u914dnginx\u7528<\/p>\n<pre><code>nginx----&gt;php-fpm(\u5185\u90e8\u8c03\u7528\u6267\u884cphp\u7684web\u5e94\u7528\u7a0b\u5e8f)<\/code><\/pre>\n<p>\u90e8\u7f72\u6848\u4f8b\u89c1&#8212;\u300bweb\u5c42\u90e8\u7f72php\u7a0b\u5e8f\uff1a<a href=\"https:\/\/egonlin.com\/?p=9154\">https:\/\/egonlin.com\/?p=9154<\/a><\/p>\n<h1>\u4e94\u3001lnmp-\u90e8\u7f72python<\/h1>\n<p>\u6709\u4e24\u5927\u7c7b\u65b9\u6848\uff0c\u5982\u4e0b<\/p>\n<h2>5.1 \u4e0d\u5728web\u5c42\u5f15\u5165nginx<\/h2>\n<p>web\u5c42\u670d\u52a1\u5668\u4e0a\uff1a\u4e0d\u90e8\u7f72nginx<br \/>\n1\u3001\u53ea\u90e8\u7f72uwsgi\uff0c\u5e76\u5f00\u542fhttp\u534f\u8bae<\/p>\n<pre><code>\u8d1f\u8f7d\u5747\u8861\u5c42\uff1a\u9700\u8981\u4f7f\u7528\u6307\u4ee4proxy_pass<\/code><\/pre>\n<p>2\u3001\u4e4b\u90e8\u7f72uwsgi\uff0c\u5e76\u5f00\u542fuwsgi\u534f\u8bae<\/p>\n<pre><code>\u8d1f\u8f7d\u5747\u8861\u5c42\uff1a\u9700\u8981\u4f7f\u7528\u6307\u4ee4uwsgi_pass<\/code><\/pre>\n<h3>5.2 \u5728web\u5c42\u5f15\u5165nginx<\/h3>\n<p>web\u5c42\u670d\u52a1\u5668\u4e0a\uff1a\u5728uwsgi\u670d\u52a1\u524d\u6321\u4e00\u4e2anginx\uff0c\u90a3\u5bf9\u5916web\u5c42\u670d\u52a1\u5668\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\u7684\u5c31\u662fnginx\uff0cnginx\u5bf9\u5916\u66b4\u6f0f\u7684\u4e00\u5b9a\u662fhttp\u534f\u8bae\u4e86<br \/>\n\u6240\u4ee5\u6b64\u65f6\u7684<\/p>\n<pre><code>\u8d1f\u8f7d\u5747\u8861\u5c42\u4e00\u5b9a\u9700\u8981\u4f7f\u7528\u6307\u4ee4proxy_pass<\/code><\/pre>\n<p>\u5177\u4f53\u5728web\u5c42\u670d\u52a1\u5668\u4e0a\u8fd8\u53ef\u4ee5\u5206\u4e24\u79cd\u60c5\u51b5\u8ba8\u8bba<br \/>\n1\u3001\u90e8\u7f72nginx\u3001\u90e8\u7f72uwsgi\u5e76\u5f00\u542fhttp\u534f\u8bae<\/p>\n<pre><code>web\u5c42\u4e0a\u7684nginx\u9700\u8981\u4f7f\u7528\u6307\u4ee4proxy_pass<\/code><\/pre>\n<p>2\u3001\u90e8\u7f72nginx\u3001\u90e8\u7f72uwsgi\u5e76\u5f00\u542fuwsgi\u534f\u8bae\uff08\u63a8\u8350\u8fd9\u79cd\u65b9\u6848\uff09<\/p>\n<pre><code>web\u5c42\u4e0a\u7684nginx\u9700\u8981\u4f7f\u7528\u6307\u4ee4uwsgi_pass<\/code><\/pre>\n<h3>5.3 \u6700\u7ec8\u65b9\u6848<\/h3>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711464908838.png'><img class=\"lazyload lazyload-style-2\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  data-original=\"https:\/\/egonlin.com\/wp-content\/uploads\/2024\/03\/image-1711464908838.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"file\" \/><\/div><\/p>\n<p>\u90e8\u7f72\u6848\u4f8b\u89c1&#8212;\u300bweb\u5c42\u90e8\u7f72python\u7a0b\u5e8f\uff1a<a href=\"https:\/\/egonlin.com\/?p=9152\">https:\/\/egonlin.com\/?p=9152<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u672c\u7ae0\u4e3b\u9898 lnmp\/lamp \u90e8\u7f72php\u8bed\u8a00\u7f16\u5199\u7684web\u5e94\u7528\u7a0b\u5e8f \u90e8\u7f72python\u8bed\u8a00\u7f16\u5199\u7684web\u5e94\u7528\u7a0b\u5e8f [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[43],"tags":[],"_links":{"self":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9002"}],"collection":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9002"}],"version-history":[{"count":29,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9002\/revisions"}],"predecessor-version":[{"id":11000,"href":"https:\/\/egonlin.com\/index.php?rest_route=\/wp\/v2\/posts\/9002\/revisions\/11000"}],"wp:attachment":[{"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9002"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9002"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/egonlin.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9002"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}