{"id":87206,"date":"2026-07-30T01:16:31","date_gmt":"2026-07-29T17:16:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/87206.html"},"modified":"2026-07-30T01:16:31","modified_gmt":"2026-07-29T17:16:31","slug":"%e8%ae%b0%e5%bd%95%e6%88%91%e7%9a%84django%e9%83%a8%e7%bd%b2%e5%88%b0%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e5%85%a8%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/87206.html","title":{"rendered":"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b"},"content":{"rendered":"<p>\u7528\u8fd9\u7bc7\u6587\u7ae0\u8bb0\u5f55\u4e00\u4e0b\u6211\u7b2c\u4e00\u6b21django\u90e8\u7f72\u8fc7\u7a0b&#xff0c;\u4ee5\u9632\u4ee5\u540e\u518d\u6b21\u90e8\u7f72\u7c7b\u4f3c\u7684\u65f6\u5019\u8981\u91cd\u65b0\u6765\u3002<\/p>\n<h2>1\u3001\u68c0\u67e5\u4fee\u6539\u540e\u7aef\u4ee3\u7801<\/h2>\n<h3>1.1\u68c0\u67e5\u4fee\u6539setting.py<\/h3>\n<p>\u68c0\u67e5ALLOWED_HOSTS &#xff0c;\u5f00\u53d1\u73af\u5883\u662fALLOWED_HOSTS &#061; [\u2018*\u2019]&#xff0c;\u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539<\/p>\n<p><span class=\"token comment\">#\u5f00\u53d1\u73af\u5883\u5141\u8bb8\u6240\u6709<\/span><br \/>\nALLOWED_HOSTS <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;*&#039;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n\u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539<\/p>\n<p>\u68c0\u67e5database&#xff0c;\u90e8\u7f72\u540e\u8981\u8bb0\u5f97\u6539\u6210\u670d\u52a1\u5668\u4e0a\u7684\u6570\u636e\u5e93\u8fde\u63a5\u4fe1\u606f<\/p>\n<p>DATABASES <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;default&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;ENGINE&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;django.db.backends.mysql&#034;<\/span>,<br \/>\n        <span class=\"token string\">&#034;NAME&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;xxx&#034;<\/span>,  <span class=\"token comment\"># \u670d\u52a1\u5668\u4e0a\u6539\u6570\u636e\u5e93\u540d<\/span><br \/>\n        <span class=\"token string\">&#034;HOST&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;localhost&#034;<\/span>,  <span class=\"token comment\"># \u670d\u52a1\u5668\u4e0a\u6539\u4e3b\u673a\u5730\u5740<\/span><br \/>\n        <span class=\"token string\">&#034;PORT&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;3306&#034;<\/span>,  <span class=\"token comment\"># \u670d\u52a1\u5668\u4e0a\u6539\u7aef\u53e3<\/span><br \/>\n        <span class=\"token string\">&#034;USER&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;root&#034;<\/span>,  <span class=\"token comment\"># \u670d\u52a1\u5668\u4e0a\u6539\u7528\u6237\u540d<\/span><br \/>\n        <span class=\"token string\">&#034;PASSWORD&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;12345678&#034;<\/span>,  <span class=\"token comment\"># \u670d\u52a1\u5668\u4e0a\u6539\u5bc6\u7801<\/span><br \/>\n        <span class=\"token string\">&#039;OPTIONS&#039;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#039;charset&#039;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#039;utf8mb4&#039;<\/span>,<br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>1.2\u68c0\u67e5\u5176\u4ed6\u7684\u6587\u4ef6<\/h3>\n<p>\u68c0\u67e5\u4e0d\u8981\u51fa\u73b0\u7edd\u5bf9\u8def\u5f84&#xff0c;\u8fd9\u4e2a\u4e0b\u6b21\u5f00\u53d1\u7684\u65f6\u5019\u8981\u8bb0\u5f97\u5f00\u53d1\u7684\u65f6\u5019\u5c31\u4e0d\u8981\u51fa\u73b0\u7edd\u5bf9\u8def\u5f84&#xff0c;\u7528\u76f8\u5bf9\u8def\u5f84&#xff0c;\u6bd4\u5982<\/p>\n<p><span class=\"token comment\"># \u274c \u539f\u6765\u7684&#xff08;\u7edd\u5bf9\u8def\u5f84&#xff09;&#xff1a;<\/span><br \/>\ncustom_dir <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;D:\/pycharm \u9879\u76ee\u5e93\/djangoProject\/static\/media\/processed_image&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u2705 \u6539\u4e3a&#xff08;\u76f8\u5bf9\u8def\u5f84&#xff09;&#xff1a;<\/span><br \/>\ncustom_dir <span class=\"token operator\">&#061;<\/span> os.path.join<span class=\"token punctuation\">(<\/span>settings.MEDIA_ROOT, <span class=\"token string\">&#039;processed_image&#039;<\/span><span class=\"token punctuation\">)<\/span>&#096;&#096;&#096;<\/p>\n<p>\u6709\u5bc6\u7801\u8fd9\u79cd\u7684\u4e0d\u8981\u51fa\u73b0\u5728\u4ee3\u7801\u91cc&#xff0c;\u6bd4\u5982\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684appid\u548csecret&#xff0c;\u6539\u6210\u5728\u670d\u52a1\u5668\u7ec8\u7aef\u7684\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e\u548c\u83b7\u53d6<\/p>\n<h2>2\u3001\u8d2d\u4e70\u670d\u52a1\u5668<\/h2>\n<p>\u6211\u662f\u5728\u963f\u91cc\u4e91\u4e0a\u8d2d\u4e70\u7684&#xff0c;\u56e0\u4e3a\u6211\u662f\u5b66\u751f\u6709\u514d\u8d39\u8bd5\u75281\u4e2a\u6708\u7684\u4f18\u60e0&#xff0c;\u5728https:\/\/www.aliyun.com\/\u4e0a\u67e5\u770b&#xff0c;\u6211\u8bd5\u7528\u7684\u662f\u8f7b\u91cf\u5e94\u7528\u670d\u52a1\u5668,\u5728\u4ea7\u54c1\u4e2d\u627e\u5230\u4e91\u670d\u52a1\u5668ECS,\u4f60\u4f1a\u770b\u5230\u6709\u514d\u8d39\u8bd5\u7528\u7684\u5b57\u6837&#xff0c;\u70b9\u51fb\u81ea\u5df1\u9009\u81ea\u5df1\u9700\u8981\u7684&#xff0c;\u6211\u9009\u62e9\u7684\u662f\u5982\u56fe\u8fd9\u4e2a<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260729171630-6a6a356e7a880.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>3\u3001\u8fc1\u79fb\u6570\u636e\u5e93<\/h2>\n<p>\u6211\u4f7f\u7528\u7684mysql&#xff0c;\u6211\u5c31\u8bb0\u5f55\u6211\u7684mysql\u6570\u636e\u5e93\u8fc1\u79fb\u8fc7\u7a0b&#xff0c;\u6211\u8fd9\u4e2a\u6709\u5b9d\u5854\u9762\u677f\u611f\u89c9\u4e0b\u4ec0\u4e48\u4e1c\u897f\u90fd\u633a\u65b9\u4fbf<\/p>\n<h3>3.1\u4e0b\u8f7dmysql<\/h3>\n<p>\u5148\u5728cmd\u8f93\u5165<\/p>\n<p>mysql &#8211;version<\/p>\n<p>\u67e5\u770b\u5f00\u53d1\u7528\u7684mysql\u7248\u672c&#xff0c;\u7136\u540e\u5728\u8f6f\u4ef6\u5546\u5e97\u4e0b\u8f7dmysql&#xff0c;\u9009\u62e9\u5bf9\u5e94\u7684\u7248\u672c\u3002\u5982\u679c\u6ca1\u6709\u5b9d\u5854\u9762\u677f\u7684\u8bdd\u6211\u4f30\u8ba1\u5c31\u95eeai\u600e\u4e48\u4e0b\u4e86\u3002\u6ca1\u6709\u76f8\u540c\u7684\u7248\u672c\u53ef\u4ee5\u9009\u62e9\u6700\u8fd1\u7684\u7248\u672c\u3002<\/p>\n<h3>3.2\u4e0b\u8f7dmysql\u53ef\u89c6\u5316<\/h3>\n<p>\u6211\u5728\u5b9d\u5854\u9762\u677f\u7684\u8f6f\u4ef6\u5546\u5e97\u91cc\u6b63\u597d\u6709phpmyadmin\u8fd9\u4e2a\u5de5\u5177&#xff0c;\u6211\u5c31\u4f7f\u7528\u7684\u8fd9\u4e2a&#xff0c;\u76f4\u63a5\u6839\u636e\u5b83\u7684\u63d0\u793a\u53bb\u4e0b\u8f7d\u9700\u8981\u7684php\u7248\u672c&#xff0c;\u4e0b\u8f7d\u5b8c\u53ef\u4ee5\u68c0\u67e5&#xff0c;\u5728\u7ec8\u7aef\u8f93\u5165<\/p>\n<p>php -v<\/p>\n<p>\u68c0\u67e5\u5b89\u88c5\u662f\u5426\u6210\u529f&#xff0c;\u7136\u540e\u63d0\u793a\u8fd8\u9700\u8981\u4e0b\u8f7dNginx \/ Apache \/ OpenLiteSpeed\u4e09\u90091&#xff0c;\u6211\u4e0b\u7684\u662fNginx&#xff0c;\u7136\u540e\u4e0b\u8f7dphpadmin\u5c31\u53ef\u4ee5\u4e86\u3002\u5982\u679c\u4e0d\u7528\u7684\u8bdd\u53ef\u4ee5\u7528dbeaver\u8fde\u63a5\u4e5f\u53ef\u4ee5\u3002<br \/>\n\u6211\u9047\u5230\u7684\u95ee\u9898\u662f\u8fd9\u4e2aphpadmin\u548cphp\u6709\u7248\u672c\u517c\u5bb9\u95ee\u9898&#xff0c;\u6211\u6700\u540e\u964d\u4f4ephp\u7248\u672c\u4e3a7.4&#xff0c;phpadmin\u662f5\u30020\u3002<\/p>\n<h3>3.3\u6570\u636e\u5e93\u8fc1\u79fb<\/h3>\n<p>\u70b9\u51fb\u9762\u677f\u91cc\u7684\u6570\u636e\u5e93&#xff0c;\u70b9\u51fb\u6dfb\u52a0\u6570\u636e\u5e93&#xff0c;\u81ea\u5df1\u5199\u8bbe\u7f6e&#xff0c;\u8bbf\u95ee\u6743\u9650\u9009\u672c\u5730\u670d\u52a1\u5668\u3002\u6dfb\u52a0\u5b8c\u6bd5\u540e\u70b9\u51fb\u7ba1\u7406\u81ea\u52a8\u8df3\u8f6cphpadmin\u767b\u5f55\u754c\u9762&#xff0c;\u8f93\u5165\u521a\u624d\u8bbe\u7f6e\u7684\u8fdb\u5165\u6570\u636e\u5e93\u754c\u9762\u3002\u5982\u679c\u5fd8\u8bb0\u4e86\u5bc6\u7801\u53ef\u4ee5\u5728\u7ec8\u7aef\u8f93\u5165<\/p>\n<p><span class=\"token comment\"># 1. \u505c\u6b62MySQL<\/span><br \/>\n<span class=\"token function\">service<\/span> mysqld stop<\/p>\n<p><span class=\"token comment\"># 2. \u5b89\u5168\u6a21\u5f0f\u542f\u52a8<\/span><br \/>\nmysqld_safe &#8211;skip-grant-tables <span class=\"token operator\">&amp;<\/span><\/p>\n<p><span class=\"token comment\"># 3. \u767b\u5f55MySQL&#xff08;\u4e0d\u7528\u5bc6\u7801&#xff09;<\/span><br \/>\nmysql -u root<\/p>\n<p><span class=\"token comment\"># 4. \u91cd\u7f6e\u5bc6\u7801<\/span><br \/>\nUSE mysql<span class=\"token punctuation\">;<\/span><br \/>\nUPDATE user SET <span class=\"token assign-left variable\">authentication_string<\/span><span class=\"token operator\">&#061;<\/span>PASSWORD<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u4f60\u7684\u65b0\u5bc6\u7801&#039;<\/span><span class=\"token punctuation\">)<\/span> WHERE <span class=\"token assign-left variable\">User<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;root&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\nFLUSH PRIVILEGES<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token builtin class-name\">exit<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\"># 5. \u91cd\u542fMySQL<\/span><br \/>\n<span class=\"token function\">service<\/span> mysqld restart<\/p>\n<p>\u5728\u672c\u5730\u7684\u6570\u636e\u5e93&#xff0c;\u5148\u521b\u5efa\u4e00\u4e2a\u548c\u4f60\u672c\u5730\u4e00\u6837\u540d\u5b57\u7684\u6570\u636e\u5e93\u518d\u5bfc\u5165&#xff0c;\u8fd9\u4e00\u6b65\u5f88\u91cd\u8981\u3002\u8981\u8fdb\u5165\u8fd9\u4e2a\u6570\u636e\u5e93\u3002\u7136\u540e\u7528\u4f60\u7684\u53ef\u89c6\u5316\u5de5\u5177\u628a\u4f60\u5f00\u53d1\u65f6\u672c\u5730\u7528\u7684\u6570\u636e\u5e93\u5bfc\u51fa\u4e3asql\u8bed\u53e5&#xff0c;\u7136\u540e\u7528\u538b\u7f29\u5de5\u5177\u538b\u7f29\u4e3azip&#xff0c;\u7136\u540e\u5728phpadmin\u754c\u9762\u9009\u62e9\u5bfc\u5165&#xff0c;\u9009\u62e9\u4f60\u7684zip\u4e0a\u4f20&#xff0c;\u7136\u540e\u70b9\u51fb\u6267\u884c\u5c31\u53ef\u4ee5\u4e86\u3002\u6210\u529f\u7684\u8bdd\u4f60\u5728\u5de6\u4fa7\u80fd\u770b\u89c1\u4f60\u672c\u5730\u5f00\u53d1\u4e00\u6837\u7684\u6570\u636e\u5e93.<\/p>\n<h2>4\u3001\u914d\u7f6e\u8fd0\u884c\u73af\u5883<\/h2>\n<h3>4.1\u4e0a\u4f20\u4ee3\u7801\u6587\u4ef6<\/h3>\n<p>\u5728\u672c\u5730\u628a\u6574\u4e2a\u9879\u76ee\u538b\u7f29\u4e3azip&#xff0c;\u7136\u540e\u5728\u5b9d\u5854\u9762\u677f\u8fdb\u5165\/www\/wwwroot\/&#xff0c;\u70b9\u51fb\u4e0a\u4f20\u5427\u9879\u76eezip\u4e0a\u4f20&#xff0c;\u5b8c\u6210\u540e\u53f3\u952e\u89e3\u538b\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<h3>4.2\u5b89\u88c5\u5bf9\u5e94python\u548cpip<\/h3>\n<p>\u5b89\u88c5pip\u548c\u7528\u672c\u5730\u5bf9\u5e94\u7248\u672c\u7684python&#xff0c;\u6211\u8fd9\u65f6\u5019\u6211\u7528\u8f6f\u4ef6\u5546\u5e97python\u7248\u672c\u6539\u4e0d\u4e86&#xff0c;\u6211\u5c31\u5728\u7ec8\u7aef\u4e0b\u8f7d\u7f16\u8bd1\u7684&#xff0c;\u6211\u8981\u7528python3.10\u3002\u7ec8\u7aef\u8f93\u5165<\/p>\n<p><span class=\"token function\">sudo<\/span> yum groupinstall -y <span class=\"token string\">&#034;Development Tools&#034;<\/span><br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> -y openssl-devel bzip2-devel libffi-devel <span class=\"token function\">wget<\/span> sqlite-devel<br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> -y gcc <span class=\"token function\">make<\/span> zlib-devel readline-devel<br \/>\n<span class=\"token comment\"># \u8fdb\u5165\u4e34\u65f6\u76ee\u5f55<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/tmp<\/p>\n<p><span class=\"token comment\"># \u4e0b\u8f7dPython 3.10.13&#xff08;\u8f83\u7a33\u5b9a\u7684\u7248\u672c&#xff09;<\/span><br \/>\n<span class=\"token function\">wget<\/span> https:\/\/www.python.org\/ftp\/python\/3.10.13\/Python-3.10.13.tgz<\/p>\n<p><span class=\"token comment\"># \u89e3\u538b<\/span><br \/>\n<span class=\"token function\">tar<\/span> -xvf Python-3.10.13.tgz<br \/>\n<span class=\"token builtin class-name\">cd<\/span> Python-3.10.13<\/p>\n<p><span class=\"token comment\"># \u914d\u7f6e\u7f16\u8bd1\u9009\u9879<\/span><br \/>\n.\/configure &#8211;enable-optimizations &#8211;enable-shared<\/p>\n<p><span class=\"token comment\"># \u7f16\u8bd1\u5b89\u88c5&#xff08;-j \u53c2\u6570\u6839\u636eCPU\u6838\u5fc3\u6570\u8c03\u6574&#xff09;<\/span><br \/>\n<span class=\"token function\">make<\/span> -j <span class=\"token variable\"><span class=\"token variable\">$(<\/span>nproc<span class=\"token variable\">)<\/span><\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">make<\/span> altinstall<\/p>\n<p><span class=\"token comment\"># \u68c0\u67e5Python 3.10\u662f\u5426\u5b89\u88c5\u6210\u529f<\/span><br \/>\npython3.10 &#8211;version<\/p>\n<p><span class=\"token comment\"># \u5982\u679c\u663e\u793a Python 3.10.13 \u8868\u793a\u6210\u529f<\/span><\/p>\n<p><span class=\"token comment\"># \u6dfb\u52a0Python\u5e93\u8def\u5f84\u5230\u7cfb\u7edf<\/span><br \/>\n<span class=\"token builtin class-name\">echo<\/span> <span class=\"token string\">&#034;\/usr\/local\/lib&#034;<\/span> <span class=\"token operator\">|<\/span> <span class=\"token function\">sudo<\/span> <span class=\"token function\">tee<\/span> \/etc\/ld.so.conf.d\/python3.10.conf<\/p>\n<p><span class=\"token comment\"># \u66f4\u65b0\u52a8\u6001\u94fe\u63a5\u5e93\u7f13\u5b58<\/span><br \/>\n<span class=\"token function\">sudo<\/span> ldconfig<br \/>\n<span class=\"token comment\"># \u9a8c\u8bc1\u914d\u7f6e<\/span><br \/>\nldconfig -p <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> python3.10<\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u8f6f\u94fe\u63a5&#xff08;\u65b9\u4fbf\u4f7f\u7528&#xff09;<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">ln<\/span> -sf \/usr\/local\/bin\/python3.10 \/usr\/local\/bin\/python3<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">ln<\/span> -sf \/usr\/local\/bin\/python3.10 \/usr\/local\/bin\/python<\/p>\n<p><span class=\"token comment\"># \u518d\u6b21\u9a8c\u8bc1<\/span><br \/>\npython3 &#8211;version<br \/>\npython &#8211;version<br \/>\n<span class=\"token comment\">#\u6210\u529f\u5c31\u7ee7\u7eed\u5b89\u88c5pip<\/span><br \/>\n<span class=\"token comment\"># \u5b89\u88c5pip<\/span><br \/>\n<span class=\"token function\">curl<\/span> -sS https:\/\/bootstrap.pypa.io\/get-pip.py <span class=\"token operator\">|<\/span> python3.10<br \/>\n<span class=\"token comment\"># \u68c0\u67e5pip\u7248\u672c<\/span><br \/>\npip3.10 &#8211;version<br \/>\npip3 &#8211;version<br \/>\n<span class=\"token comment\"># \u5b89\u88c5virtualenv<\/span><br \/>\npip3.10 <span class=\"token function\">install<\/span> virtualenv<\/p>\n<p><span class=\"token comment\"># \u9a8c\u8bc1virtualenv<\/span><br \/>\nvirtualenv &#8211;version<\/p>\n<p>\u5176\u4e2d\u6211\u9047\u5230\u7684\u95ee\u9898&#xff0c;\u5728# \u7f16\u8bd1\u5b89\u88c5&#xff08;-j \u53c2\u6570\u6839\u636eCPU\u6838\u5fc3\u6570\u8c03\u6574&#xff09;<br \/>\nmake -j $(nproc)<br \/>\nsudo make altinstall\u7684\u65f6\u5019\u5f88\u6162&#xff0c;\u662f\u6b63\u5e38\u7684&#xff0c;\u8981\u8010\u5fc3\u7b49\u3002\u7136\u540e\u68c0\u67e5pip\u7248\u672c\u90fd\u6ca1\u95ee\u9898\u7684\u8bdd&#xff0c;\u8bb0\u5f97\u540e\u9762pip\u4e0b\u8f7d\u8981\u7528pip3,\u4e0d\u7136\u4f1a\u663e\u793a\u6ca1\u6709pip\u3002<\/p>\n<h3>4.3\u7528requirement\u4e0b\u8f7d\u73af\u5883<\/h3>\n<p>\u6211\u8fd9\u4e2a\u662f\u7528yolov11\u8bc6\u522b\u7684django\u9879\u76ee&#xff0c;\u6240\u4ee5\u6211\u6709\u4e2a\u95ee\u9898\u5c31\u662f\u8fd9\u4e2arequirement\u592a\u5927\u4e86&#xff0c;\u6709\u5f88\u591a\u6ca1\u6709\u7528\u5230&#xff0c;\u6211\u7684\u89e3\u51b3\u65b9\u6cd5\u662f\u628a\u6211\u7684\u6240\u67091\u4ee3\u7801\u7ed9ai\u8ba9\u5b83\u7ed9\u6211\u5199\u4e00\u4e2a\u7cbe\u7b80\u7248\u7684requirement\u3002\u4e0d\u7528\u62c5\u5fc3\u4f1a\u4e0d\u4f1a\u5c11&#xff0c;\u5c11\u73af\u5883\u8fd0\u884c\u4f1a\u63d0\u9192\u4f60&#xff0c;\u4f60\u518d\u52a0\u4e0a\u9700\u8981\u7684\u5c31\u518d\u91cd\u4e0b\u5c31\u884c\u4e86\u3002<br \/>\nrequirement\u51c6\u5907\u597d\u5c31\u53ef\u4ee5\u7ee7\u7eed\u3002<\/p>\n<p><span class=\"token comment\">#\u5148cd\u5230requirement\u8def\u5f84<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/www\/wwwroot\/djangoProject<br \/>\n<span class=\"token comment\">#\u7528pip\u4e0b\u8f7d\u73af\u5883<\/span><br \/>\npip <span class=\"token function\">install<\/span> -r requirements.txt<\/p>\n<p>\u5982\u679c\u6709\u4ec0\u4e48\u95ee\u9898\u8981\u5220\u9664\u4e4b\u524d\u4e0b\u8f7d\u7684&#xff0c;<\/p>\n<p><span class=\"token comment\">#\u5378\u8f7d\u5355\u4e2a\u5305<\/span><br \/>\npip uninstall package_name<br \/>\n<span class=\"token comment\">#\u5378\u8f7drequirement\u91cc\u7684\u6240\u6709\u5305<\/span><br \/>\npip uninstall -r requirements.txt -y<br \/>\n<span class=\"token comment\"># \u5378\u8f7d\u591a\u4e2a\u5305<\/span><br \/>\npip uninstall package1 package2 package3<br \/>\n<span class=\"token comment\"># \u6216\u4f7f\u7528\u5faa\u73af<\/span><br \/>\n<span class=\"token keyword\">for<\/span> <span class=\"token for-or-select variable\">package<\/span> <span class=\"token keyword\">in<\/span> package1 package2 package3<span class=\"token punctuation\">;<\/span> <span class=\"token keyword\">do<\/span><br \/>\n    pip uninstall -y <span class=\"token variable\">$package<\/span><br \/>\n<span class=\"token comment\">#\u9000\u51fasql<\/span><br \/>\n<span class=\"token keyword\">done<\/span><\/p>\n<p>\u9047\u5230\u7684\u95ee\u98981&#xff1a;note: This error originates from a subprocess, and is likely not a problem with pip.<br \/>\n\u8fd9\u4e2a\u9519\u8bef\u8868\u660e\u7cfb\u7edf\u7f3a\u5c11 MySQL \u5ba2\u6237\u7aef\u5f00\u53d1\u5e93\u3002<br \/>\n\u89e3\u51b3\u65b9\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u5b89\u88c5 MySQL \u5f00\u53d1\u5305<\/span><br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> mysql-devel<\/p>\n<p><span class=\"token comment\"># \u6216\u8005\u5982\u679c\u4e0a\u9762\u4e0d\u884c&#xff0c;\u5c1d\u8bd5&#xff1a;<\/span><br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> mariadb-devel<\/p>\n<p><span class=\"token comment\"># \u5982\u679c\u4f7f\u7528 Amazon Linux 2:<\/span><br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> mysql-devel gcc python3-devel<br \/>\n<span class=\"token comment\">#\u7136\u540e\u5b89\u88c5python\u5f00\u53d1\u5305<\/span><br \/>\n<span class=\"token comment\"># CentOS\/RHEL<\/span><br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> python3-devel<\/p>\n<p><span class=\"token comment\"># Ubuntu\/Debian<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> <span class=\"token function\">install<\/span> python3-dev<br \/>\n<span class=\"token comment\">#\u5b89\u88c5\u6784\u5efa\u5de5\u5177<\/span><br \/>\n<span class=\"token comment\"># CentOS\/RHEL<\/span><br \/>\n<span class=\"token function\">sudo<\/span> yum <span class=\"token function\">install<\/span> gcc<\/p>\n<p><span class=\"token comment\"># Ubuntu\/Debian<\/span><br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt-get<\/span> <span class=\"token function\">install<\/span> build-essential<br \/>\n<span class=\"token comment\">#\u6e05\u7406\u7f13\u5b58\u540e\u91cd\u65b0\u5b89\u88c5<\/span><br \/>\n<span class=\"token comment\"># \u6e05\u7406 pip \u7f13\u5b58<\/span><br \/>\npython3 -m pip cache purge<\/p>\n<p><span class=\"token comment\"># \u91cd\u65b0\u5b89\u88c5 requirements.txt<\/span><br \/>\npython3 -m pip <span class=\"token function\">install<\/span> -r requirements.txt<\/p>\n<p>\u4e0b\u8f7d\u5b8c\u5728\u9879\u76ee\u6587\u4ef6\u5939\u91cc\u65b0\u5efa\u4e00\u4e2apy\u6d4b\u8bd5mysql\u8fd8\u6709\u6ca1\u6709\u95ee\u9898<\/p>\n<p><span class=\"token shebang important\">#!\/usr\/bin\/env python3<\/span><br \/>\n<span class=\"token function\">import<\/span> MySQLdb<\/p>\n<p>try:<br \/>\n    <span class=\"token comment\"># \u4f7f\u7528\u6b63\u786e\u7684\u914d\u7f6e<\/span><br \/>\n    conn <span class=\"token operator\">&#061;<\/span> MySQLdb.connect<span class=\"token punctuation\">(<\/span><br \/>\n        <span class=\"token assign-left variable\">host<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;localhost&#039;<\/span>,<br \/>\n        <span class=\"token assign-left variable\">user<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u7528\u6237\u540d&#039;<\/span>,<br \/>\n        <span class=\"token assign-left variable\">passwd<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u5bc6\u7801&#039;<\/span>,<br \/>\n        <span class=\"token assign-left variable\">db<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;\u6570\u636e\u5e93\u540d\u5b57&#039;<\/span>,<br \/>\n        <span class=\"token assign-left variable\">port<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">3306<\/span>,<br \/>\n        <span class=\"token assign-left variable\">charset<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;utf8mb4&#039;<\/span><br \/>\n    <span class=\"token punctuation\">)<\/span><\/p>\n<p>    print<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u2705 \u6570\u636e\u5e93\u8fde\u63a5\u6210\u529f&#xff01;&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u6d4b\u8bd5\u67e5\u8be2<\/span><br \/>\n    cursor <span class=\"token operator\">&#061;<\/span> conn.cursor<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u68c0\u67e5 django_migrations \u8868<\/span><br \/>\n    cursor.execute<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;SELECT COUNT(*) FROM django_migrations&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    result <span class=\"token operator\">&#061;<\/span> cursor.fetchone<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    print<span class=\"token punctuation\">(<\/span>f<span class=\"token string\">&#039;\u2705 django_migrations \u8868\u4e2d\u6709 {result[0]} \u6761\u8bb0\u5f55&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u68c0\u67e5 auth_user \u8868<\/span><br \/>\n    cursor.execute<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;SELECT COUNT(*) FROM auth_user&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    result <span class=\"token operator\">&#061;<\/span> cursor.fetchone<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    print<span class=\"token punctuation\">(<\/span>f<span class=\"token string\">&#039;\u2705 auth_user \u8868\u4e2d\u6709 {result[0]} \u6761\u7528\u6237\u8bb0\u5f55&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5217\u51fa\u6240\u6709\u8868<\/span><br \/>\n    cursor.execute<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;SHOW TABLES&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    tables <span class=\"token operator\">&#061;<\/span> cursor.fetchall<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    print<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u2705 \u6570\u636e\u5e93\u4e2d\u7684\u8868&#xff1a;&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> i, table <span class=\"token keyword\">in<\/span> enumerate<span class=\"token punctuation\">(<\/span>tables, <span class=\"token number\">1<\/span><span class=\"token punctuation\">)<\/span>:<br \/>\n        print<span class=\"token punctuation\">(<\/span>f<span class=\"token string\">&#039;  {i:2d}. {table[0]}&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    cursor.close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    conn.close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>except MySQLdb.Error as e:<br \/>\n    print<span class=\"token punctuation\">(<\/span>f<span class=\"token string\">&#039;\u274c MySQL \u8fde\u63a5\u9519\u8bef: {e}&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    print<span class=\"token punctuation\">(<\/span>f<span class=\"token string\">&#039;  \u9519\u8bef\u4ee3\u7801: {e.args[0]}&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    print<span class=\"token punctuation\">(<\/span>f<span class=\"token string\">&#039;  \u9519\u8bef\u4fe1\u606f: {e.args[1]}&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nexcept Exception as e:<br \/>\n    print<span class=\"token punctuation\">(<\/span>f<span class=\"token string\">&#039;\u274c \u5176\u4ed6\u9519\u8bef: {e}&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u65b0\u5efa\u5b8c\u5728\u7ec8\u7aef\u8fd0\u884c\u8fd9\u4e2apy\u6d4b\u8bd5\u662f\u5426\u4fee\u597d<br \/>\n\u95ee\u98982&#xff1a; MySQL \u8fde\u63a5\u9519\u8bef: (2002, \u201cCan\u2019t connect to local MySQL server through socket \u2018\/var\/lib\/mysql\/mysql.sock\u2019 (2)\u201d)<br \/>\n\u9519\u8bef\u4ee3\u7801: 2002<br \/>\n\u9519\u8bef\u4fe1\u606f: Can\u2019t connect to local MySQL server through socket \u2018\/var\/lib\/mysql\/mysql.sock\u2019 (2)<br \/>\n\u89e3\u51b3\u65b9\u6cd5\u5982\u4e0b&#xff1a;<br \/>\n\u6211\u5728\u7ec8\u7aef\u6267\u884c\u68c0\u67e5<\/p>\n<p><span class=\"token comment\"># \u5c1d\u8bd5\u542f\u52a8 MySQL&#xff08;\u6839\u636e\u4f60\u770b\u5230\u7684\u670d\u52a1\u540d&#xff09;<\/span><br \/>\nsystemctl start mysqld<br \/>\n<span class=\"token comment\"># \u6216\u8005<\/span><br \/>\nsystemctl start mysql<\/p>\n<p><span class=\"token comment\"># \u8bbe\u7f6e\u5f00\u673a\u81ea\u542f<\/span><br \/>\nsystemctl <span class=\"token builtin class-name\">enable<\/span> mysqld<br \/>\nsystemctl <span class=\"token builtin class-name\">enable<\/span> mysql<\/p>\n<p><span class=\"token comment\"># \u518d\u6b21\u68c0\u67e5\u72b6\u6001<\/span><br \/>\nsystemctl status mysqld<\/p>\n<p>\u53d1\u73b0\u62a5\u9519[root&#064;iZ2zeccueqitwdmdo2s0nnZ djangoProject]# ls -la \/var\/lib\/mysql\/mysql.sock 2&gt;\/dev\/null || echo \u201cmysql.sock \u4e0d\u5b58\u5728\u201d<br \/>\nmysql.sock \u4e0d\u5b58\u5728<br \/>\n[root&#064;iZ2zeccueqitwdmdo2s0nnZ djangoProject]# find \/ -name \u201c*.sock\u201d 2&gt;\/dev\/null | grep mysql<br \/>\n\/tmp\/mysql.sock<br \/>\n\/tmp\/mysqlx.sock&#xff0c;\u95ee\u9898\u662fMySQL \u6b63\u5728\u8fd0\u884c&#xff0c;\u4f46\u662f socket \u6587\u4ef6\u5728 \/tmp\/mysql.sock \u800c\u4e0d\u662f\u9ed8\u8ba4\u7684 \/var\/lib\/mysql\/mysql.sock&#xff0c;\u6211\u5c31\u6307\u5b9asock\u8def\u5f84\u3002<br \/>\n\u5728\u6211\u9879\u76ee\u91cc\u7684setting\u91cc\u4fee\u6539\u6570\u636e\u5e93\u6307\u5b9asock\u8def\u5f84\u5c31\u89e3\u51b3\u4e86\u3002<\/p>\n<p>DATABASES <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;default&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;ENGINE&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;django.db.backends.mysql&#034;<\/span>,<br \/>\n        <span class=\"token string\">&#034;NAME&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;xxx&#034;<\/span>,<br \/>\n        <span class=\"token string\">&#034;USER&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;xxx&#034;<\/span>,<br \/>\n        <span class=\"token string\">&#034;PASSWORD&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;xxx&#034;<\/span>,<br \/>\n        <span class=\"token string\">&#034;HOST&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;127.0.0.1&#034;<\/span>,  <span class=\"token comment\"># \u6216\u8005\u4fdd\u6301 localhost<\/span><br \/>\n        <span class=\"token string\">&#034;PORT&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;3306&#034;<\/span>,<br \/>\n        <span class=\"token string\">&#034;OPTIONS&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#034;init_command&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;SET sql_mode&#061;&#039;STRICT_TRANS_TABLES&#039;&#034;<\/span>,<br \/>\n            <span class=\"token string\">&#034;unix_socket&#034;<\/span><span class=\"token builtin class-name\">:<\/span> <span class=\"token string\">&#034;\/tmp\/mysql.sock&#034;<\/span>,  <span class=\"token comment\"># \u6dfb\u52a0\u8fd9\u884c\u6307\u5b9a socket \u8def\u5f84<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u95ee\u98983&#xff0c;\u5982\u679c\u662f\u7528\u6237\u6709\u95ee\u9898\u53ef\u4ee5\u5728\u7ec8\u7aef\u8fdb\u5165mysql&#xff0c;\u7528sql\u8bed\u53e5\u4fee\u6539<\/p>\n<p><span class=\"token comment\"># \u9996\u5148\u4f7f\u7528\u7528\u6237\u767b\u5f55 MySQL<\/span><br \/>\nmysql -u \u7528\u6237\u540d -p\u5bc6\u7801 -S \/tmp\/mysql.sock<br \/>\n&#8212; \u67e5\u770b\u6240\u6709\u7528\u6237<br \/>\nSELECT user, <span class=\"token function\">host<\/span> FROM mysql.user<span class=\"token punctuation\">;<\/span><br \/>\n&#8212; \u67e5\u770b\u6570\u636e\u5e93\u7684\u6743\u9650<br \/>\nSELECT * FROM mysql.db WHERE Db <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\u6570\u636e\u5e93\u540d\u5b57&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n&#8212; \u6388\u4e88\u5bf9 zimu \u6570\u636e\u5e93\u7684\u6240\u6709\u6743\u9650<br \/>\nGRANT ALL PRIVILEGES ON \u6570\u636e\u5e93\u540d\u5b57.* TO <span class=\"token string\">&#039;\u7528\u6237\u540d&#039;<\/span>&#064;<span class=\"token string\">&#039;localhost&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\nGRANT ALL PRIVILEGES ON \u6570\u636e\u5e93\u540d\u5b57.* TO <span class=\"token string\">&#039;\u7528\u6237\u540d&#039;<\/span>&#064;<span class=\"token string\">&#039;%&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n&#8212; \u5237\u65b0\u6743\u9650<br \/>\nFLUSH PRIVILEGES<span class=\"token punctuation\">;<\/span><\/p>\n<p>&#8212; \u518d\u6b21\u67e5\u770b\u6743\u9650\u786e\u8ba4<br \/>\nSHOW GRANTS FOR <span class=\"token string\">&#039;\u7528\u6237\u540d&#039;<\/span>&#064;<span class=\"token string\">&#039;localhost&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token builtin class-name\">exit<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h3>4.4\u6d4b\u8bd5django\u662f\u5426\u80fd\u8fd0\u884c<\/h3>\n<p>\u7ec8\u7aef\u6267\u884c<\/p>\n<p><span class=\"token comment\"># \u6d4b\u8bd5\u5f00\u53d1\u670d\u52a1\u5668&#xff08;Ctrl&#043;C \u505c\u6b62&#xff09;<\/span><br \/>\npython3 manage.py runserver <span class=\"token number\">0.0<\/span>.0.0:8000<\/p>\n<p>\u5982\u679c\u7ec8\u7aef\u8f93\u51fa\u548c\u5f00\u53d1\u65f6\u8f93\u51fa\u4e00\u6837\u90a3\u5c31\u662f\u90e8\u7f72\u5168\u90e8\u6210\u529f\u4e86\u3002\u53ef\u4ee5\u7528\u4e0b\u9762\u7684\u6307\u4ee4\u6d4b\u8bd5\u63a5\u53e3\u662f\u5426\u6b63\u5e38<\/p>\n<p><span class=\"token function\">curl<\/span> -v <span class=\"token string\">&#034;\u4f60\u7684url&#034;<\/span><\/p>\n<p>\u9047\u5230\u7684\u95ee\u98981&#xff1a;\u6211\u8fd0\u884c\u53d1\u73b0\u7f3a\u5c11opencv\u5e93&#xff0c;\u539f\u56e0\u662f\u6211\u7684requirement\u91cc\u662fopencv-python-headless&#xff1a;\u65e0 GUI \u7248\u672c&#xff0c;\u7f3a\u5c11 libGL.so.1&#xff0c;\u9700\u8981\u7684\u662fopencv-python&#xff1a;\u5b8c\u6574\u7248&#xff0c;\u5305\u542b GUI \u652f\u6301&#xff0c;\u9700\u8981\u56fe\u5f62\u5e93<br \/>\n\u89e3\u51b3\u65b9\u6cd5&#xff1a;<br \/>\n\u6539\u6210opencv-python&#061;&#061;4.13.0.90\u7136\u540e\u7ec8\u7aef\u8fd0\u884c<\/p>\n<p><span class=\"token comment\"># 1. \u5b89\u88c5\u56fe\u5f62\u5e93\u4f9d\u8d56&#xff08;\u5fc5\u987b\u5148\u505a&#xff09;<\/span><br \/>\nyum <span class=\"token function\">install<\/span> -y mesa-libGL libXrender libXext libSM libICE libX11<\/p>\n<p><span class=\"token comment\"># 2. \u76f4\u63a5\u5b89\u88c5 requirements.txt<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/www\/wwwroot\/djangoProject<br \/>\npip <span class=\"token function\">install<\/span> -r requirements.txt<\/p>\n<p><span class=\"token comment\"># 3. \u6d4b\u8bd5<\/span><br \/>\npython3 -c <span class=\"token string\">&#034;import cv2; print(&#039;OpenCV OK&#039;)&#034;<\/span> <span class=\"token operator\">&amp;&amp;<\/span> python3 manage.py check<\/p>\n<h2>5\u3001\u4f7f\u7528Gunicorn\u542f\u52a8\u751f\u4ea7\u670d\u52a1\u5668<\/h2>\n<h3>\u5b89\u88c5Gunicorn\u548c\u4f9d\u8d56<\/h3>\n<p>\u5148\u505c\u6b62\u5f00\u53d1\u670d\u52a1\u5668<\/p>\n<p><span class=\"token comment\"># 1. \u627e\u5230\u5e76\u505c\u6b62\u6b63\u5728\u8fd0\u884c\u7684Django\u5f00\u53d1\u670d\u52a1\u5668<\/span><br \/>\n<span class=\"token function\">ps<\/span> aux <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> runserver<\/p>\n<p><span class=\"token comment\"># 2. \u5982\u679c\u6709\u57288000\u7aef\u53e3\u8fd0\u884c\u7684\u8fdb\u7a0b&#xff0c;\u505c\u6b62\u5b83<\/span><br \/>\n<span class=\"token comment\"># \u4f7f\u7528pkill&#xff08;\u5982\u679c\u77e5\u9053\u5177\u4f53\u8fdb\u7a0b&#xff09;<\/span><br \/>\n<span class=\"token function\">pkill<\/span> -f <span class=\"token string\">&#034;runserver&#034;<\/span><br \/>\n<span class=\"token comment\"># 3. \u786e\u8ba48000\u7aef\u53e3\u5df2\u91ca\u653e<\/span><br \/>\n<span class=\"token function\">netstat<\/span> -tlnp <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> :8000<\/p>\n<p>\u7136\u540e\u7ec8\u7aef\u6267\u884c\u6765\u5b89\u88c5Gunicorn<\/p>\n<p><span class=\"token comment\"># \u8fdb\u5165\u9879\u76ee\u76ee\u5f55<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/www\/wwwroot\/djangoProject<br \/>\n<span class=\"token comment\"># \u5b89\u88c5\u751f\u4ea7\u73af\u5883\u4f9d\u8d56<\/span><br \/>\npip3 <span class=\"token function\">install<\/span> gunicorn gevent<\/p>\n<h3>\u521b\u5efaGunicorn\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u5728\u9879\u76ee\u6587\u4ef6\u5939\u91cc\u521b\u5efagunicorn_config.py<\/p>\n<p><span class=\"token function\">import<\/span> multiprocessing<\/p>\n<p><span class=\"token comment\"># 1. \u7f51\u7edc\u7ed1\u5b9a<\/span><br \/>\n<span class=\"token builtin class-name\">bind<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;127.0.0.1:8001&#034;<\/span>  <span class=\"token comment\"># Nginx\u4ee3\u7406\u5230\u8fd9\u4e2a\u7aef\u53e3<\/span><\/p>\n<p><span class=\"token comment\"># 2. \u5de5\u4f5c\u8fdb\u7a0b\u6570&#xff08;\u6839\u636e\u670d\u52a1\u5668CPU\u8c03\u6574&#xff09;<\/span><br \/>\nworkers <span class=\"token operator\">&#061;<\/span> multiprocessing.cpu_count<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> * <span class=\"token number\">2<\/span> &#043; <span class=\"token number\">1<\/span>  <span class=\"token comment\"># \u4f60\u76842\u6838\u670d\u52a1\u5668 &#061; 5\u4e2aworker<\/span><\/p>\n<p><span class=\"token comment\"># 3. \u5de5\u4f5c\u6a21\u5f0f&#xff08;gevent\u5904\u7406\u5e76\u53d1\u66f4\u597d&#xff09;<\/span><br \/>\nworker_class <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;gevent&#034;<\/span><br \/>\nworker_connections <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1000<\/span>  <span class=\"token comment\"># \u6bcf\u4e2aworker\u6700\u5927\u5e76\u53d1<\/span><\/p>\n<p><span class=\"token comment\"># 4. \u8d85\u65f6\u8bbe\u7f6e&#xff08;\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u53ef\u80fd\u9700\u8981\u957f\u65f6\u95f4\u8fde\u63a5&#xff09;<\/span><br \/>\n<span class=\"token function\">timeout<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">120<\/span><br \/>\nkeepalive <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span><\/p>\n<p><span class=\"token comment\"># 5. \u91cd\u542f\u7b56\u7565&#xff08;\u9632\u6b62\u5185\u5b58\u6cc4\u6f0f&#xff09;<\/span><br \/>\nmax_requests <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1000<\/span><br \/>\nmax_requests_jitter <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">50<\/span><\/p>\n<p><span class=\"token comment\"># 6. \u65e5\u5fd7\u914d\u7f6e<\/span><br \/>\naccesslog <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\/www\/wwwroot\/djangoProject\/logs\/gunicorn_access.log&#034;<\/span><br \/>\nerrorlog <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\/www\/wwwroot\/djangoProject\/logs\/gunicorn_error.log&#034;<\/span><br \/>\nloglevel <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;info&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 7. \u6027\u80fd\u4f18\u5316<\/span><br \/>\npreload_app <span class=\"token operator\">&#061;<\/span> True  <span class=\"token comment\"># \u9884\u52a0\u8f7d\u5e94\u7528&#xff0c;\u542f\u52a8\u5feb<\/span><br \/>\nreload <span class=\"token operator\">&#061;<\/span> False  <span class=\"token comment\"># \u751f\u4ea7\u73af\u5883\u4e0d\u81ea\u52a8\u91cd\u8f7d<\/span><\/p>\n<p><span class=\"token comment\"># 8. \u8fdb\u7a0b\u540d&#xff08;\u65b9\u4fbf\u7ba1\u7406&#xff09;<\/span><br \/>\nproc_name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;django_api&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 9. \u8fde\u63a5\u961f\u5217<\/span><br \/>\nbacklog <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2048<\/span><\/p>\n<p>\u7136\u540e\u521b\u5efa\u65e5\u5fd7\u76ee\u5f55<\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u65e5\u5fd7\u548c\u8fd0\u884c\u76ee\u5f55<\/span><br \/>\n<span class=\"token function\">mkdir<\/span> -p \/www\/wwwroot\/djangoProject\/logs<br \/>\n<span class=\"token function\">mkdir<\/span> -p \/www\/wwwroot\/djangoProject\/run<\/p>\n<p><span class=\"token comment\"># \u8bbe\u7f6e\u6743\u9650<\/span><br \/>\n<span class=\"token function\">chown<\/span> -R www:www \/www\/wwwroot\/djangoProject\/logs<br \/>\n<span class=\"token function\">chmod<\/span> -R <span class=\"token number\">755<\/span> \/www\/wwwroot\/djangoProject\/logs<\/p>\n<p>\u6d4b\u8bd5\u8fd0\u884c&#xff0c;\u6309ctrl&#043;c\u505c\u6b62<\/p>\n<p><span class=\"token builtin class-name\">cd<\/span> \/www\/wwwroot\/djangoProject<br \/>\ngunicorn -c gunicorn_config.py api.djangoProject.wsgi:application<\/p>\n<p>\u76d1\u63a7\u547d\u4ee4\u6709&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u67e5\u770b\u5b9e\u65f6\u65e5\u5fd7<\/span><br \/>\n<span class=\"token function\">sudo<\/span> journalctl -u django-gunicorn -f<\/p>\n<p><span class=\"token comment\"># \u6216\u67e5\u770b\u6587\u4ef6\u65e5\u5fd7<\/span><br \/>\n<span class=\"token function\">tail<\/span> -f \/www\/wwwroot\/djangoProject\/logs\/gunicorn_access.log<\/p>\n<p><span class=\"token comment\"># \u67e5\u770b\u8fdb\u7a0b<\/span><br \/>\n<span class=\"token function\">ps<\/span> aux <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> gunicorn<\/p>\n<p><span class=\"token comment\"># \u67e5\u770b\u7aef\u53e3<\/span><br \/>\n<span class=\"token function\">netstat<\/span> -tlnp <span class=\"token operator\">|<\/span> <span class=\"token function\">grep<\/span> :8001<\/p>\n<p>\u6211\u9047\u5230\u7684\u95ee\u98981&#xff1a;Gunicorn\u627e\u4e0d\u5230\u6b63\u786ePython\u8def\u5f84\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5&#xff1a;\u7ec8\u7aef\u8fd0\u884c\u8fd9\u4e9b\u77e5\u9053\u771f\u5b9ePython\u7248\u672c\u548c\u8def\u5f84\u4ee5\u53ca\u76f4\u63a5\u8fd0\u884cgunicorn\u7684\u7ed3\u679c\u3002<\/p>\n<p><span class=\"token function\">which<\/span> python3 <span class=\"token operator\">&amp;&amp;<\/span> python3 &#8211;version <span class=\"token operator\">&amp;&amp;<\/span> pip3 show django<br \/>\n\/usr\/bin\/python3 -m gunicorn &#8211;bind <span class=\"token number\">127.0<\/span>.0.1:8001 djangoProject.wsgi:application<\/p>\n<p>\u7136\u540e\u4fee\u6539gunicorn_config.py\u5f3a\u5236\u4f7f\u7528\u6b63\u786epython\u8def\u5f84\u3002\u6211\u7684\u662f\u8fd9\u6837\u7684&#xff1a;<\/p>\n<p><span class=\"token shebang important\">#!\/usr\/bin\/env python3<\/span><br \/>\n<span class=\"token function\">import<\/span> os<br \/>\n<span class=\"token function\">import<\/span> sys<\/p>\n<p><span class=\"token comment\"># \u5f3a\u5236\u4f7f\u7528Python 3.10\u8def\u5f84<\/span><br \/>\nsys.path.insert<span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span>, <span class=\"token string\">&#039;\/www\/wwwroot\/djangoProject&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nsys.path.insert<span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span>, <span class=\"token string\">&#039;\/usr\/local\/lib\/python3.10\/site-packages&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\nsys.path.insert<span class=\"token punctuation\">(<\/span><span class=\"token number\">0<\/span>, <span class=\"token string\">&#039;\/usr\/lib64\/python3.10\/site-packages&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u544a\u8bc9Gunicorn\u4f7f\u7528\u54ea\u4e2aPython<\/span><br \/>\npythonpath <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;\/usr\/local\/bin\/python3&#039;<\/span><\/p>\n<p><span class=\"token comment\"># Gunicorn\u914d\u7f6e<\/span><br \/>\n<span class=\"token builtin class-name\">bind<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;127.0.0.1:8001&#034;<\/span><br \/>\nworkers <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">3<\/span><br \/>\nworker_class <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;gevent&#034;<\/span><br \/>\n<span class=\"token function\">timeout<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">120<\/span><br \/>\nkeepalive <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">2<\/span><\/p>\n<p><span class=\"token comment\"># \u65e5\u5fd7<\/span><br \/>\naccesslog <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\/www\/wwwroot\/djangoProject\/logs\/gunicorn_access.log&#034;<\/span><br \/>\nerrorlog <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;\/www\/wwwroot\/djangoProject\/logs\/gunicorn_error.log&#034;<\/span><br \/>\nloglevel <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;info&#034;<\/span><\/p>\n<p><span class=\"token comment\"># \u6027\u80fd<\/span><br \/>\npreload_app <span class=\"token operator\">&#061;<\/span> True<br \/>\nmax_requests <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1000<\/span><br \/>\nmax_requests_jitter <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">50<\/span><\/p>\n<p><span class=\"token comment\"># \u8fdb\u7a0b\u540d<\/span><br \/>\nproc_name <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;django_api&#034;<\/span><\/p>\n<p>\u518d\u8fd0\u884c\u6d4b\u8bd5\u5c31\u53ef\u4ee5\u4e86\u3002<br \/>\n\u95ee\u98982&#xff1a;Python\u73af\u5883\u6709Django\u4f46\u6ca1\u6709Gunicorn\u3002\u7ec8\u7aef\u6267\u884c<\/p>\n<p><span class=\"token comment\"># 1. \u5148\u68c0\u67e5<\/span><br \/>\n<span class=\"token function\">which<\/span> gunicorn<br \/>\ngunicorn &#8211;version<\/p>\n<p><span class=\"token comment\"># 2. \u5982\u679c\u6ca1\u6709&#xff0c;\u5b89\u88c5<\/span><br \/>\n\/usr\/bin\/pip3 <span class=\"token function\">install<\/span> gunicorn gevent &#8211;force-reinstall<\/p>\n<p><span class=\"token comment\"># 3. \u9a8c\u8bc1<\/span><br \/>\n\/usr\/local\/bin\/python3 -c <span class=\"token string\">&#034;import gunicorn; print(&#039;\u6210\u529f&#039;)&#034;<\/span><\/p>\n<p><span class=\"token comment\"># 4. \u6d4b\u8bd5\u542f\u52a8<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/www\/wwwroot\/djangoProject<br \/>\ngunicorn &#8211;bind <span class=\"token number\">127.0<\/span>.0.1:8001 djangoProject.wsgi:application<\/p>\n<h2>6\u3001\u914d\u7f6eNginx\u53cd\u5411\u4ee3\u7406<\/h2>\n<h3>6.1\u5728\u5b9d\u5854\u9762\u677f\u6dfb\u52a0\u7f51\u7ad9<\/h3>\n<p>\u5728\u5b9d\u5854\u9762\u677f\u6dfb\u52a0\u7f51\u7ad9<br \/>\n\u767b\u5f55\u5b9d\u5854\u9762\u677f&#xff0c;\u70b9\u51fb\u5de6\u4fa7\u300c\u7f51\u7ad9\u300d\u2192\u300c\u6dfb\u52a0\u7ad9\u70b9\u300d<br \/>\n\u586b\u5199&#xff1a;\u57df\u540d&#xff1a;&#xff08;\u4f60\u7684IP&#xff09;<br \/>\n\u6839\u76ee\u5f55&#xff1a;\/www\/wwwroot\/djangoProject<br \/>\nPHP\u7248\u672c&#xff1a;\u9009\u62e9\u300c\u7eaf\u9759\u6001\u300d<br \/>\n\u5176\u4ed6\u9ed8\u8ba4<br \/>\n\u70b9\u51fb\u300c\u63d0\u4ea4\u300d<br \/>\n\u6211\u4eec\u4f9d\u65e7\u4f1a\u652f\u6301flowchart.js\u7684\u6d41\u7a0b\u56fe\u8bed\u6cd5&#xff1a;<\/p>\n<h3>6.2\u914d\u7f6eNginx\u53cd\u5411\u4ee3\u7406<\/h3>\n<p>\u70b9\u51fb\u521a\u521b\u5efa\u7684\u7f51\u7ad9 \u2192 \u300c\u8bbe\u7f6e\u300d<br \/>\n\u70b9\u51fb\u300c\u53cd\u5411\u4ee3\u7406\u300d\u2192\u300c\u6dfb\u52a0\u53cd\u5411\u4ee3\u7406\u300d<br \/>\n\u586b\u5199&#xff1a;\u4ee3\u7406\u540d\u79f0&#xff1a;django_api<br \/>\n\u76ee\u6807URL&#xff1a;http:\/\/127.0.0.1:8001<br \/>\n\u5176\u4ed6\u9ed8\u8ba4<br \/>\n\u70b9\u51fb\u300c\u63d0\u4ea4\u300d<\/p>\n<h3>6.3\u4fee\u6539Nginx\u914d\u7f6e<\/h3>\n<p>\u70b9\u51fb\u521a\u521b\u5efa\u7684\u7f51\u7ad9 \u2192 \u300c\u8bbe\u7f6e\u300d<br \/>\n\u70b9\u51fb\u300c\u914d\u7f6e\u6587\u4ef6\u300d&#xff0c;\u4ed6\u6709\u5df2\u7ecf\u5199\u597d\u7684&#xff0c;\u627e\u5230include \/www\/server\/panel\/vhost\/nginx\/proxy\/47.93.186.129\/*.conf;\u4e0b\u9762\u6dfb\u52a0\u53cd\u5411\u4ee3\u7406\u8bbe\u7f6e&#xff0c;\u6211\u7684\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u524d\u7aef\u6240\u4ee5\u662f\u5982\u4e0b\u8fd9\u6837&#xff0c;\u5177\u4f53\u8981\u6839\u636e\u81ea\u5df1\u7684\u60c5\u51b5\u4fee\u6539<\/p>\n<p><span class=\"token comment\"># &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; Django \u53cd\u5411\u4ee3\u7406\u914d\u7f6e &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/span><\/p>\n<p><span class=\"token comment\"># \u9759\u6001\u6587\u4ef6 &#8211; \u5bf9\u5e94\u4f60\u7684 STATIC_ROOT<\/span><br \/>\nlocation \/static\/ <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token builtin class-name\">alias<\/span> \/www\/wwwroot\/djangoProject\/static\/<span class=\"token punctuation\">;<\/span><br \/>\n    expires 30d<span class=\"token punctuation\">;<\/span><br \/>\n    access_log off<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\"># \u5a92\u4f53\u6587\u4ef6 &#8211; \u5bf9\u5e94\u4f60\u7684 MEDIA_ROOT<\/span><br \/>\nlocation \/media\/ <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token builtin class-name\">alias<\/span> \/www\/wwwroot\/djangoProject\/static\/media\/<span class=\"token punctuation\">;<\/span>  <span class=\"token comment\"># \u4f60\u7684\u914d\u7f6e<\/span><br \/>\n    expires 30d<span class=\"token punctuation\">;<\/span><br \/>\n    access_log off<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\"># \u4e3bAPI\u4ee3\u7406&#xff08;\u7b80\u5316\u7248&#xff09;<\/span><br \/>\nlocation \/ <span class=\"token punctuation\">{<\/span><br \/>\n    proxy_pass http:\/\/127.0.0.1:8001<span class=\"token punctuation\">;<\/span><br \/>\n    proxy_set_header Host <span class=\"token variable\">$host<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    proxy_set_header X-Real-IP <span class=\"token variable\">$remote_addr<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    proxy_set_header X-Forwarded-For <span class=\"token variable\">$proxy_add_x_forwarded_for<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    proxy_set_header X-Forwarded-Proto <span class=\"token variable\">$scheme<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u8d85\u65f6\u8bbe\u7f6e<\/span><br \/>\n    proxy_connect_timeout 60s<span class=\"token punctuation\">;<\/span><br \/>\n    proxy_send_timeout 60s<span class=\"token punctuation\">;<\/span><br \/>\n    proxy_read_timeout 120s<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5fae\u4fe1\u5c0f\u7a0b\u5e8fCORS<\/span><br \/>\n    add_header Access-Control-Allow-Origin <span class=\"token string\">&#039;https:\/\/servicewechat.com&#039;<\/span> always<span class=\"token punctuation\">;<\/span><br \/>\n    add_header Access-Control-Allow-Methods <span class=\"token string\">&#039;GET, POST, PUT, DELETE, OPTIONS&#039;<\/span> always<span class=\"token punctuation\">;<\/span><br \/>\n    add_header Access-Control-Allow-Headers <span class=\"token string\">&#039;Content-Type, Authorization, X-CSRFToken, X-Requested-With, X-WX-Code, X-WX-Encrypted-Data, X-WX-IV&#039;<\/span> always<span class=\"token punctuation\">;<\/span><br \/>\n    add_header Access-Control-Allow-Credentials <span class=\"token string\">&#039;true&#039;<\/span> always<span class=\"token punctuation\">;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5904\u7406OPTIONS\u9884\u68c0\u8bf7\u6c42<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token variable\">$request_method<\/span> <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#039;OPTIONS&#039;<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        add_header Access-Control-Allow-Origin <span class=\"token string\">&#039;https:\/\/servicewechat.com&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        add_header Access-Control-Allow-Methods <span class=\"token string\">&#039;GET, POST, PUT, DELETE, OPTIONS&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        add_header Access-Control-Allow-Headers <span class=\"token string\">&#039;Content-Type, Authorization, X-CSRFToken, X-Requested-With, X-WX-Code, X-WX-Encrypted-Data, X-WX-IV&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        add_header Access-Control-Allow-Credentials <span class=\"token string\">&#039;true&#039;<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        add_header Content-Length <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        add_header Content-Type text\/plain<span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token builtin class-name\">return<\/span> <span class=\"token number\">204<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token comment\"># &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061; \u914d\u7f6e\u7ed3\u675f &#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;&#061;<\/span><br \/>\n<span class=\"token comment\">#\u5982\u679c\u4e0d\u9700\u8981php\u5c31\u627e\u5230\u7c7b\u4f3c<\/span><br \/>\ninclude enable-php.conf<span class=\"token punctuation\">;<\/span>\u7684\u6ce8\u91ca\u6389.<\/p>\n<p>\u9047\u5230\u7684\u95ee\u9898&#xff1a;\u4fdd\u5b58\u5931\u8d25&#xff0c;\u56e0\u4e3a\u68c0\u6d4b\u5230\u88ab\u4fee\u6539\u7684\u914d\u7f6e\u6587\u4ef6\u5b58\u5728\u9519\u8bef:<br \/>\nnginx version: nginx\/1.26.1<br \/>\nnginx: [emerg] duplicate location \u201c\/\u201d in \/www\/server\/panel\/vhost\/nginx\/47.93.186.129.conf:48<br \/>\nnginx: configuration file \/www\/server\/nginx\/conf\/nginx.conf test failed<br \/>\n\u9519\u8bef\u662f\u56e0\u4e3a\u6709\u91cd\u590d\u7684 location \/ \u914d\u7f6e&#xff0c;\u5220\u9664\u5c31\u884c&#xff0c;\u4fee\u6539\u540e\u91cd\u542fnginx\u3002<\/p>\n<p><span class=\"token comment\"># \u505c\u6b62\u6240\u6709Nginx\u8fdb\u7a0b<\/span><br \/>\n<span class=\"token function\">pkill<\/span> nginx<\/p>\n<p><span class=\"token comment\"># \u7b49\u5f852\u79d2<\/span><br \/>\n<span class=\"token function\">sleep<\/span> <span class=\"token number\">2<\/span><\/p>\n<p><span class=\"token comment\"># \u518d\u542f\u52a8<\/span><br \/>\nnginx<\/p>\n<p>\u73b0\u5728\u7528\u521a\u624d\u7684\u65b9\u6cd5\u6d4b\u8bd5\u540e\u7aef\u63a5\u53e3&#xff0c;\u5e94\u8be5\u53ef\u4ee5\u6210\u529f\u83b7\u53d6\u4e86\u3002<\/p>\n<h2>7\u3001\u914d\u7f6eSSL\u8bc1\u4e66<\/h2>\n<p>\u914d\u7f6e\u8fd9\u4e2a\u624d\u80fd\u4f7f\u7528https\u8bbf\u95ee\u7f51\u9875\u3002\u5728\u5b9d\u5854\u754c\u9762\u627e\u5230\u7f51\u7ad9&#xff0c;\u6dfb\u52a0\u7ad9\u70b9&#xff0c;\u7136\u540e\u70b9\u51fb\u8bbe\u7f6e&#xff0c;\u627e\u5230ssl&#xff0c;\u7533\u8bf7\u8bc1\u4e66\u5c31\u53ef\u4ee5\u4e86\u3002\u4f46\u662f\u5f88\u8d35\u3002<br \/>\n\u6211\u7684\u7533\u8bf7\u7684\u662f\u6d4b\u8bd5\u8bc1\u4e66&#xff0c;\u8fd9\u4e2a\u9700\u8981\u4f60\u6709\u57df\u540d&#xff0c;\u5728\u963f\u91cc\u4e91\u7f51\u9875\u91cc\u7533\u8bf7\u5c31\u53ef\u4ee5\u4e86\u8fd9\u4e2a\u5f88\u4fbf\u5b9c&#xff0c;\u4f46\u662f\u9700\u8981\u5907\u6848&#xff0c;\u9700\u8981\u7b49\u5f85\u5907\u6848\u6210\u529f\u3002<br \/>\n\u4ee5\u540e\u4f7f\u7528\u7684\u6d41\u7a0b&#xff0c;\u767b\u5f55\u9762\u677f&#xff0c;\u7ec8\u7aef\u8f93\u5165<\/p>\n<p><span class=\"token comment\"># \u767b\u5f55\u670d\u52a1\u5668<\/span><br \/>\n<span class=\"token function\">ssh<\/span> root&#064;47.93.186.129<\/p>\n<p><span class=\"token comment\"># \u8fdb\u5165\u9879\u76ee\u76ee\u5f55<\/span><br \/>\n<span class=\"token builtin class-name\">cd<\/span> \/www\/wwwroot\/djangoProject<\/p>\n<p><span class=\"token comment\"># \u505c\u6b62\u4e4b\u524d\u53ef\u80fd\u8fd0\u884c\u7684Gunicorn<\/span><br \/>\n<span class=\"token function\">pkill<\/span> -f gunicorn<\/p>\n<p><span class=\"token comment\"># \u542f\u52a8Gunicorn&#xff08;\u751f\u4ea7\u73af\u5883&#xff09;<\/span><br \/>\ngunicorn -c gunicorn_config.py djangoProject.wsgi:application <span class=\"token operator\">&amp;<\/span><\/p>\n<p><span class=\"token comment\"># \u6216\u8005\u7b80\u5355\u542f\u52a8<\/span><br \/>\ngunicorn &#8211;bind <span class=\"token number\">127.0<\/span>.0.1:8001 &#8211;workers <span class=\"token number\">3<\/span> &#8211;worker-class<span class=\"token operator\">&#061;<\/span>sync djangoProject.wsgi:application <span class=\"token operator\">&amp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7528\u8fd9\u7bc7\u6587\u7ae0\u8bb0\u5f55\u4e00\u4e0b\u6211\u7b2c\u4e00\u6b21django\u90e8\u7f72\u8fc7\u7a0b&#xff0c;\u4ee5\u9632\u4ee5\u540e\u518d\u6b21\u90e8\u7f72\u7c7b\u4f3c\u7684\u65f6\u5019\u8981\u91cd\u65b0\u6765\u3002<br \/>\n1\u3001\u68c0\u67e5\u4fee\u6539\u540e\u7aef\u4ee3\u7801<br \/>\n1.1\u68c0\u67e5\u4fee\u6539setting.py<br \/>\n\u68c0\u67e5ALLOWED_HOSTS &#xff0c;\u5f00\u53d1\u73af\u5883\u662fALLOWED_HOSTS  [\u2018*\u2019]&#xff0c;\u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539<br \/>\n#\u5f00\u53d1\u73af\u5883\u5141\u8bb8\u6240\u6709<br \/>\nALLOWED_HOSTS  [*]<br \/>\n\u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539\u68c0\u67e5database&amp;#xff0<\/p>\n","protected":false},"author":2,"featured_media":87205,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[890,81,43],"topic":[],"class_list":["post-87206","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-django","tag-python","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/87206.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u7528\u8fd9\u7bc7\u6587\u7ae0\u8bb0\u5f55\u4e00\u4e0b\u6211\u7b2c\u4e00\u6b21django\u90e8\u7f72\u8fc7\u7a0b&#xff0c;\u4ee5\u9632\u4ee5\u540e\u518d\u6b21\u90e8\u7f72\u7c7b\u4f3c\u7684\u65f6\u5019\u8981\u91cd\u65b0\u6765\u3002 1\u3001\u68c0\u67e5\u4fee\u6539\u540e\u7aef\u4ee3\u7801 1.1\u68c0\u67e5\u4fee\u6539setting.py \u68c0\u67e5ALLOWED_HOSTS &#xff0c;\u5f00\u53d1\u73af\u5883\u662fALLOWED_HOSTS [\u2018*\u2019]&#xff0c;\u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539 #\u5f00\u53d1\u73af\u5883\u5141\u8bb8\u6240\u6709 ALLOWED_HOSTS [*] \u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539\u68c0\u67e5database&amp;#xff0\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/87206.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-29T17:16:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260729171630-6a6a356e7a880.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/87206.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/87206.html\",\"name\":\"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-29T17:16:31+00:00\",\"dateModified\":\"2026-07-29T17:16:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/87206.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/87206.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/87206.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/87206.html","og_locale":"zh_CN","og_type":"article","og_title":"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u7528\u8fd9\u7bc7\u6587\u7ae0\u8bb0\u5f55\u4e00\u4e0b\u6211\u7b2c\u4e00\u6b21django\u90e8\u7f72\u8fc7\u7a0b&#xff0c;\u4ee5\u9632\u4ee5\u540e\u518d\u6b21\u90e8\u7f72\u7c7b\u4f3c\u7684\u65f6\u5019\u8981\u91cd\u65b0\u6765\u3002 1\u3001\u68c0\u67e5\u4fee\u6539\u540e\u7aef\u4ee3\u7801 1.1\u68c0\u67e5\u4fee\u6539setting.py \u68c0\u67e5ALLOWED_HOSTS &#xff0c;\u5f00\u53d1\u73af\u5883\u662fALLOWED_HOSTS [\u2018*\u2019]&#xff0c;\u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539 #\u5f00\u53d1\u73af\u5883\u5141\u8bb8\u6240\u6709 ALLOWED_HOSTS [*] \u751f\u4ea7\u73af\u5883\u8981\u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u9700\u8981\u4fee\u6539&#xff0c;\u6216\u8005\u4e0d\u4fee\u6539\u68c0\u67e5database&amp;#xff0","og_url":"https:\/\/www.wsisp.com\/helps\/87206.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-29T17:16:31+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/07\/20260729171630-6a6a356e7a880.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"8 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/87206.html","url":"https:\/\/www.wsisp.com\/helps\/87206.html","name":"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-29T17:16:31+00:00","dateModified":"2026-07-29T17:16:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/87206.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/87206.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/87206.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u8bb0\u5f55\u6211\u7684django\u90e8\u7f72\u5230\u670d\u52a1\u5668\u7684\u5168\u6d41\u7a0b"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/87206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=87206"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/87206\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/87205"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=87206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=87206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=87206"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=87206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}