{"id":9368,"date":"2025-04-18T17:23:21","date_gmt":"2025-04-18T09:23:21","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/9368.html"},"modified":"2025-04-18T17:23:21","modified_gmt":"2025-04-18T09:23:21","slug":"%e5%b0%86-fastapi-%e9%83%a8%e7%bd%b2%e5%88%b0%e7%94%9f%e4%ba%a7%e6%9c%8d%e5%8a%a1%e5%99%a8%ef%bc%88%e4%b8%80%e5%a5%97-%e5%85%a8%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/9368.html","title":{"rendered":"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09"},"content":{"rendered":"<h2>\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668&#xff08;\u5168&#xff09;<\/h2>\n<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668&#xff08;\u5168&#xff09;<\/li>\n<li>\u4e00\u3001\u524d\u8a00<\/li>\n<li>\u4e8c\u3001Fastapi\u9879\u76ee \u751f\u4ea7\u73af\u5883\u914d\u7f6e<\/li>\n<li>\n<ul>\n<li>1. \u51c6\u5907\u73af\u5883<\/li>\n<li>2. \u7f16\u5199 FastAPI \u5e94\u7528<\/li>\n<li>3. \u4f7f\u7528 Uvicorn \u8fd0\u884c\u5e94\u7528<\/li>\n<li>4. \u914d\u7f6e\u751f\u4ea7\u7ea7\u670d\u52a1\u5668 Gunicorn<\/li>\n<li>\n<ul>\n<li>4.1 \u914d\u7f6e Gunicorn \u548c Uvicorn Workers<\/li>\n<\/ul>\n<\/li>\n<li>5. \u4f7f\u7528 Supervisor \u7ba1\u7406\u5e94\u7528<\/li>\n<\/ul>\n<\/li>\n<li>\u4e09\u3001\u52a0SSl\u8bc1\u4e66\u914d\u7f6ehttps<\/li>\n<li>\n<ul>\n<li>1\u3001\u5c06\u57df\u540d\u89e3\u6790\u5230\u4f60\u7684\u670d\u52a1\u5668<\/li>\n<li>2\u3001\u9a8c\u8bc1\u8be5\u57df\u540d\u662f\u5426\u89e3\u6790\u6210\u529f<\/li>\n<li>3\u3001let&#039;s Encrypt \u8bc1\u4e66\u7533\u8bf7<\/li>\n<li>\n<ul>\n<li>&#xff08;1&#xff09;certbot\u5b89\u88c5<\/li>\n<li>&#xff08;2&#xff09;let&#039;s Encrypt \u8bc1\u4e66\u7533\u8bf7<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u56db\u3001\u914d\u7f6enginx<\/li>\n<li>\n<ul>\n<li>1\u3001nginx\u5b89\u88c5<\/li>\n<li>2\u3001\u914d\u7f6enginx.conf<\/li>\n<li>3\u3001\u91cd\u65b0\u8fd0\u884cnginx<\/li>\n<\/ul>\n<\/li>\n<li>\u4e94\u3001\u8fd0\u884c\u6d4b\u8bd5<\/li>\n<li>\n<ul>\n<li>1\u3001\u67e5\u770b\u8fd9\u4e2a\u670d\u52a1\u8f93\u51fa\u7684\u65e5\u5fd7<\/li>\n<li>2\u3001\u8bbf\u95ee\u7f51\u7ad9<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e00\u3001\u524d\u8a00<\/h2>\n<p>\u672a\u6765\u7684\u5f00\u53d1\u8005\u4eec\u8bf7\u4e0a\u5ea7\u3002 \u4ee5\u4e0b\u662f\u672c\u6b21\u7528\u5230\u7684FastAPI&#xff0c;Uvicorn&#xff0c;Gunicorn\u548cSupervisor\u7684\u7b80\u8981\u4ecb\u7ecd&#xff1a;<\/p>\n<li>\n<p>FastAPI&#xff1a;FastAPI \u662f\u4e00\u4e2a\u73b0\u4ee3\u3001\u5feb\u901f&#xff08;\u9ad8\u6027\u80fd&#xff09;\u7684 web \u6846\u67b6&#xff0c;\u7528\u4e8e\u6784\u5efa APIs&#xff0c;\u57fa\u4e8e Python 3.6&#043; \u7c7b\u578b\u63d0\u793a\u3002\u4e3b\u8981\u7279\u6027\u5305\u62ec&#xff1a;<\/p>\n<ul>\n<li>\u5feb\u901f&#xff1a;\u975e\u5e38\u9ad8\u7684\u6027\u80fd&#xff0c;\u63a5\u8fd1\u4e8e NodeJS \u548c Go&#xff08;\u7531 Starlette \u548c Pydantic \u63d0\u4f9b&#xff09;\u3002<\/li>\n<li>\u5feb\u901f\u7f16\u7801&#xff1a;\u63d0\u9ad8\u5f00\u53d1\u901f\u5ea6\u7ea6 200&#xff05; \u81f3 300&#xff05;*\u3002<\/li>\n<li>\u5c11\u51fa\u9519&#xff1a;\u51cf\u5c11\u7ea6 40&#xff05; \u7684\u4eba\u4e3a&#xff08;\u5f00\u53d1\u8005&#xff09;\u9519\u8bef\u3002<\/li>\n<li>\u76f4\u89c2&#xff1a;\u4f18\u79c0\u7684\u7f16\u8f91\u5668\u652f\u6301&#xff0c;\u2764\ufe0f \u7684\u5f00\u53d1\u4f53\u9a8c\u3002<\/li>\n<li>\u6613\u4e8e\u4f7f\u7528&#xff1a;\u8bbe\u8ba1\u6613\u4e8e\u4f7f\u7528\u548c\u5b66\u4e60&#xff0c;\u5c3d\u91cf\u51cf\u5c11\u5f00\u53d1\u65f6\u95f4\u3002<\/li>\n<li>\u7b80\u6d01&#xff1a;\u6700\u5c0f\u5316\u4ee3\u7801\u590d\u6742\u6027&#xff0c;\u5c3d\u91cf\u51cf\u5c11\u5f00\u53d1\u8005\u773c\u4e2d\u7684 bug\u3002<\/li>\n<li>\u57fa\u4e8e\u6807\u51c6&#xff1a;\u57fa\u4e8e&#xff08;\u5e76\u5b8c\u5168\u517c\u5bb9&#xff09;\u5f00\u653e\u6807\u51c6&#xff1a;OpenAPI&#xff08;\u4ee5\u524d\u79f0\u4e3a Swagger&#xff09;\u548c JSON Schema\u3002<\/li>\n<li>Django \u98ce\u683c\u7684 ORM&#xff1a;\u652f\u6301 Tortoise-ORM \u548c Pydantic \u6a21\u578b\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Uvicorn&#xff1a;Uvicorn \u662f\u4e00\u4e2a\u57fa\u4e8e asyncio \u7684 ASGI \u670d\u52a1\u5668&#xff0c;\u7528\u4e8e\u90e8\u7f72 Python \u7684\u5f02\u6b65 web \u5e94\u7528&#xff0c;\u5b83\u7684\u76ee\u6807\u662f\u6210\u4e3a Python \u5f02\u6b65\u670d\u52a1\u5668\u7f51\u5173\u63a5\u53e3&#xff08;ASGI&#xff09;\u89c4\u8303\u7684\u6700\u5feb\u5b9e\u73b0\u4e4b\u4e00\u3002Uvicorn \u652f\u6301 HTTP\/1.1 \u548c WebSockets&#xff0c;\u5e76\u4e14\u53ef\u4ee5\u914d\u5408\u50cf Starlette \u548c FastAPI \u8fd9\u6837\u7684\u6846\u67b6\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>Gunicorn&#xff1a;Gunicorn \u2018Green Unicorn\u2019 \u662f\u4e00\u4e2a Python WSGI HTTP \u670d\u52a1\u5668&#xff0c;\u7528\u4e8e UNIX\u3002\u5b83\u662f Ruby \u7684 Unicorn \u670d\u52a1\u5668\u7684 Python \u79fb\u690d\u7248\u3002Gunicorn \u7684\u5de5\u4f5c\u6a21\u5f0f\u662f\u9884\u5148\u5206\u53c9\u51fa\u591a\u4e2a\u8fdb\u7a0b\u6765\u5904\u7406\u8bf7\u6c42&#xff0c;\u8fd9\u4f7f\u5f97\u5b83\u5728\u5904\u7406\u5e76\u53d1\u8bf7\u6c42\u65f6\u5177\u6709\u8f83\u9ad8\u7684\u6548\u7387\u3002\u7136\u800c&#xff0c;\u7531\u4e8e\u5b83\u57fa\u4e8e\u540c\u6b65\u7684 WSGI&#xff0c;\u56e0\u6b64\u5728\u5904\u7406 WebSockets \u6216\u957f\u8fde\u63a5\u65f6\u53ef\u80fd\u4e0d\u5982 Uvicorn \u9ad8\u6548\u3002<\/p>\n<\/li>\n<li>\n<p>Supervisor&#xff1a;Supervisor \u662f\u4e00\u4e2a\u7528 Python \u5f00\u53d1\u7684\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177&#xff0c;\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u7528\u6765\u5728 UNIX-like \u7cfb\u7edf&#xff08;\u4e0d\u652f\u6301 Windows&#xff09;\u4e0b\u542f\u52a8\u3001\u91cd\u542f&#xff08;\u81ea\u52a8&#xff09;\u548c\u5173\u95ed\u8fdb\u7a0b&#xff08;\u7a0b\u5e8f&#xff09;\u3002\u9664\u4e86\u5bf9\u5355\u4e2a\u8fdb\u7a0b\u7684\u7ba1\u7406\u5916&#xff0c;\u8fd8\u53ef\u4ee5\u540c\u65f6\u542f\u52a8\u3001\u5173\u95ed\u591a\u4e2a\u8fdb\u7a0b&#xff0c;\u5b9e\u73b0\u5bf9\u7a0b\u5e8f\u7684\u6279\u91cf\u7ba1\u7406\u3002Supervisor \u901a\u5e38\u88ab\u7528\u4e8e\u7ba1\u7406\u670d\u52a1\u5668\u4e0a\u7684\u540e\u53f0\u7a0b\u5e8f\u3002<\/p>\n<\/li>\n<p>\u6bcf\u4e2a\u5de5\u5177\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7528\u9014&#xff1a;FastAPI \u7528\u4e8e\u6784\u5efa API&#xff0c;Uvicorn \u548c Gunicorn \u7528\u4e8e\u90e8\u7f72\u5e94\u7528&#xff0c;\u800c Supervisor \u7528\u4e8e\u8fdb\u7a0b\u7ba1\u7406\u3002\u5728 Python \u7684 web \u5f00\u53d1\u4e2d&#xff0c;\u8fd9\u4e9b\u5de5\u5177\u7ecf\u5e38\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<h2>\u4e8c\u3001Fastapi\u9879\u76ee \u751f\u4ea7\u73af\u5883\u914d\u7f6e<\/h2>\n<h3>1. \u51c6\u5907\u73af\u5883<\/h3>\n<ul>\n<li>\u64cd\u4f5c\u7cfb\u7edf&#xff1a;\u5efa\u8bae\u4f7f\u7528 Ubuntu\u3001Debian \u6216 CentOS \u7b49\u670d\u52a1\u5668\u64cd\u4f5c\u7cfb\u7edf\u3002<\/li>\n<li>Python \u73af\u5883&#xff1a;\u5b89\u88c5 Python 3.7&#043;&#xff0c;\u5e76\u521b\u5efa\u865a\u62df\u73af\u5883\u6765\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\u3002<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> update<br \/>\n<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> python3 python3-venv python3-pip <span class=\"token parameter variable\">-y<\/span><br \/>\npython3 <span class=\"token parameter variable\">-m<\/span> venv venv<br \/>\n<span class=\"token builtin class-name\">source<\/span> venv\/bin\/activate<br \/>\npip <span class=\"token function\">install<\/span> fastapi uvicorn\n <\/li>\n<\/ul>\n<hr \/>\n<h3>2. \u7f16\u5199 FastAPI \u5e94\u7528<\/h3>\n<p>\u786e\u4fdd\u4f60\u7684 FastAPI \u5e94\u7528\u6587\u4ef6&#xff08;\u5982 app.py&#xff09;\u7ed3\u6784\u6e05\u6670\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastapi <span class=\"token keyword\">import<\/span> FastAPI<br \/>\n<span class=\"token keyword\">from<\/span> fastapi<span class=\"token punctuation\">.<\/span>middleware<span class=\"token punctuation\">.<\/span>cors <span class=\"token keyword\">import<\/span> CORSMiddleware<br \/>\n<span class=\"token keyword\">from<\/span> contextlib <span class=\"token keyword\">import<\/span> asynccontextmanager<br \/>\n<span class=\"token decorator annotation punctuation\">&#064;asynccontextmanager<\/span><br \/>\n<span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">lifespan<\/span><span class=\"token punctuation\">(<\/span>app<span class=\"token punctuation\">:<\/span>FastAPI<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u521d\u59cb\u5316\u9636\u6bb5<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u521d\u59cb\u5316\u6210\u529f..&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">yield<\/span><br \/>\n    <span class=\"token comment\"># \u6e05\u7406\u9636\u6bb5<\/span><br \/>\n<span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;\u5378\u8f7d\u6210\u529f..&#039;<\/span><span class=\"token punctuation\">)<\/span><br \/>\napp <span class=\"token operator\">&#061;<\/span> FastAPI<span class=\"token punctuation\">(<\/span>root_path<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;\/aiCentre&#034;<\/span><br \/>\n<span class=\"token punctuation\">,<\/span>lifespan<span class=\"token operator\">&#061;<\/span>lifespan<br \/>\n<span class=\"token punctuation\">)<\/span> <span class=\"token comment\"># aicentre\u4e3anginx\u4e2dapi\u8def\u7531\u540d<\/span><br \/>\n<span class=\"token comment\"># \u542f\u7528CORS\u652f\u6301<\/span><br \/>\napp<span class=\"token punctuation\">.<\/span>add_middleware<span class=\"token punctuation\">(<\/span><br \/>\n    CORSMiddleware<span class=\"token punctuation\">,<\/span><br \/>\n    allow_origins<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;*&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    allow_credentials<span class=\"token operator\">&#061;<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    allow_methods<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;*&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\"># \u6216\u8005\u53ea\u5217\u51fa [&#034;POST&#034;, &#034;GET&#034;, &#034;OPTIONS&#034;, &#8230;] \u7b49<\/span><br \/>\n    allow_headers<span class=\"token operator\">&#061;<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;*&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token comment\"># \u8def\u7531<\/span><br \/>\n<span class=\"token decorator annotation punctuation\">&#064;app<span class=\"token punctuation\">.<\/span>get<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\/&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">read_root<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;message&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;Welcome to FastAPI!&#034;<\/span><span class=\"token punctuation\">}<\/span><\/p>\n<p>\u6ce8&#xff1a;nginx.conf\u4e2d\u540e\u7aef\u914d\u7f6e\u53c2\u8003\u5982\u4e0b\u5982\u4e0b&#xff0c;\u6ce8\u610froot_path\u548c\u8def\u7531\u8981\u4e00\u81f4\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092315-68021a03415ed.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<hr \/>\n<h3>3. \u4f7f\u7528 Uvicorn \u8fd0\u884c\u5e94\u7528<\/h3>\n<p>\u5148\u5728\u5f00\u53d1\u73af\u5883\u6d4b\u8bd5\u8fd0\u884c&#xff1a;<\/p>\n<p>uvicorn app:app <span class=\"token parameter variable\">&#8211;host<\/span> <span class=\"token number\">0.0<\/span>.0.0 <span class=\"token parameter variable\">&#8211;port<\/span> <span class=\"token number\">8000<\/span><\/p>\n<p>\u8bbf\u95ee http:\/\/&lt;\u4f60\u7684\u670d\u52a1\u5668IP&gt;:8000&#xff0c;\u786e\u8ba4\u5e94\u7528\u6b63\u5e38\u3002<\/p>\n<hr \/>\n<h3>4. \u914d\u7f6e\u751f\u4ea7\u7ea7\u670d\u52a1\u5668 Gunicorn<\/h3>\n<p>\u751f\u4ea7\u73af\u5883\u901a\u5e38\u9700\u8981\u4f7f\u7528\u53cd\u5411\u4ee3\u7406&#xff08;\u5982 Nginx&#xff09;\u548c\u8fdb\u7a0b\u7ba1\u7406\u5668&#xff08;\u5982 Gunicorn \u3001 Supervisor&#xff09;\u3002<\/p>\n<h4>4.1 \u914d\u7f6e Gunicorn \u548c Uvicorn Workers<\/h4>\n<p>\u5b89\u88c5 Gunicorn&#xff0c;\u5e76\u914d\u7f6e\u591a\u8fdb\u7a0b\u652f\u6301&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> gunicorn uvicorn<br \/>\ngunicorn app:app <span class=\"token parameter variable\">-w<\/span> <span class=\"token number\">4<\/span> <span class=\"token parameter variable\">-k<\/span> uvicorn.workers.UvicornWorker <span class=\"token parameter variable\">&#8211;bind<\/span> <span class=\"token number\">0.0<\/span>.0.0:8000<\/p>\n<p>\u8bbf\u95ee http:\/\/&lt;\u4f60\u7684\u670d\u52a1\u5668IP&gt;:8000&#xff0c;\u786e\u8ba4\u5e94\u7528\u6b63\u5e38&#xff0c;Gunicorn\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<ul>\n<li>-w 4&#xff1a;\u6307\u5b9a 4 \u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u3002<\/li>\n<li>-k uvicorn.workers.UvicornWorker&#xff1a;\u4f7f\u7528 Uvicorn Worker\u3002<\/li>\n<li>app:app&#xff0c;\u7b2c\u4e00\u4e2aapp\u662fpython\u6587\u4ef6\u540d&#xff0c;\u7b2c\u4e8c\u4e2a\u662fFastAPI\u7684\u5b9e\u4f8b\u5316\u7684\u5bf9\u8c61\u540d\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>5. \u4f7f\u7528 Supervisor \u7ba1\u7406\u5e94\u7528<\/h3>\n<p>\u4e3a\u786e\u4fdd\u5e94\u7528\u5728\u670d\u52a1\u5668\u91cd\u542f\u540e\u81ea\u52a8\u8fd0\u884c&#xff0c;\u53ef\u4ee5\u4f7f\u7528 Supervisor\u3002<\/p>\n<li>\u5b89\u88c5 Supervisor&#xff1a;<span class=\"token function\">sudo<\/span> <span class=\"token function\">apt<\/span> <span class=\"token function\">install<\/span> supervisor <span class=\"token parameter variable\">-y<\/span>\n <\/li>\n<li>\u521b\u5efa\u914d\u7f6e\u6587\u4ef6 \/etc\/supervisor\/conf.d\/fastapi.conf&#xff1a;[program:fastapi]<br \/>\ncommand&#061;\/path\/to\/venv\/bin\/gunicorn app:app -w 4 -k uvicorn.workers.UvicornWorker &#8211;bind 127.0.0.1:8000<br \/>\ndirectory&#061;\/path\/to\/your\/project<br \/>\nuser&#061;youruser<br \/>\nautostart&#061;true<br \/>\nautorestart&#061;true<br \/>\nstderr_logfile&#061;\/var\/log\/fastapi.err.log<br \/>\nstdout_logfile&#061;\/var\/log\/fastapi.out.log\n <\/li>\n<li>\u542f\u7528\u914d\u7f6e\u5e76\u542f\u52a8&#xff1a;<span class=\"token function\">sudo<\/span> supervisorctl reread<br \/>\n<span class=\"token function\">sudo<\/span> supervisorctl update<br \/>\n<span class=\"token function\">sudo<\/span> supervisorctl start fastapi\n <\/li>\n<p>\u6ce81&#xff1a;\u6bcf\u4e00\u6b21\u66f4\u6539\u90fd\u9700\u8981\u90fd\u6267\u884c\u4e00\u904d\u3002<\/p>\n<p>\u6ce82&#xff1a;fastapi\u8fd9\u4e2a\u8981\u6c42\u662f\u6587\u4ef6\u540dfastapi.conf \u548c [program:fastapi]\u4e00\u81f4&#xff0c;\u53ef\u4ee5\u66f4\u6362\u4e3a\u4f60\u7684<\/p>\n<hr \/>\n<h2>\u4e09\u3001\u52a0SSl\u8bc1\u4e66\u914d\u7f6ehttps<\/h2>\n<p>\u524d\u7f6e\u6761\u4ef6&#xff1a;\u6211\u9ed8\u8ba4\u4f60\u5df2\u7ecf\u6709\u57df\u540d\u4e86&#xff0c;\u5982\u679c\u6ca1\u6709\u9700\u8981\u5728\u56fd\u5185\u7684\u963f\u91cc\u4e91\u3001\u817e\u8baf\u4e91\u3001\u534e\u4e3a\u4e91&#xff0c;\u56fd\u5916\u7684Hostinger\u7b49\u4e91\u670d\u52a1\u5546\u90fd\u63d0\u4f9b\u57df\u540d\u6ce8\u518c\u548c\u57df\u540d\u89e3\u6790\u670d\u52a1\u3002\u627e\u4e00\u4e2a\u4f60\u559c\u6b22\u7684\u5c31\u53ef\u4ee5&#xff0c;\u5728\u8fd9\u91cc\u6211\u7528\u7684\u662f\u963f\u91cc\u4e91\u6ce8\u518c\u7684\u57df\u540d\u8fdb\u884c\u6f14\u793a\u3002 &#xff08;\u56fd\u5185\u7684\u57df\u540d\u9700\u8981\u63d0\u524d\u5907\u6848&#xff0c;15\u5929\u5de6\u53f3\u3002\u5982\u679c\u6bd4\u8f83\u7740\u6025\u4e14\u53ea\u662f\u6f14\u793a\u53ef\u4ee5\u7528\u9999\u6e2f\u6216\u8005\u56fd\u5916\u5982Hostinger \u4e91\u670d\u52a1\u5382\u5546\u63d0\u4f9b\u7684\u57df\u540d\u8fd9\u6837\u53ef\u4ee5\u514d\u6389\u5907\u6848\u7684\u6b65\u9aa4&#xff09;<\/p>\n<h3>1\u3001\u5c06\u57df\u540d\u89e3\u6790\u5230\u4f60\u7684\u670d\u52a1\u5668<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092315-68021a036afad.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u7b49\u5f8520s\u5de6\u53f3\u8ba9\u5176\u4f20\u64ad\u3002<\/p>\n<h3>2\u3001\u9a8c\u8bc1\u8be5\u57df\u540d\u662f\u5426\u89e3\u6790\u6210\u529f<\/h3>\n<p>\u6267\u884c nslookup &#043; \u57df\u540d&#xff0c;\u5373\u53ef\u67e5\u8be2\u57df\u540d\u89e3\u6790\u5bf9\u8c61<\/p>\n<p>nslookup bak.sligenai.cn<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092316-68021a0467ce7.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u770b\u5230\u89e3\u6790\u5230\u4f60\u7684\u516c\u7f51\u670d\u52a1\u5668\u7684ip\u5c31\u5b8c\u6210\u4e86<\/p>\n<h3>3\u3001let\u2019s Encrypt \u8bc1\u4e66\u7533\u8bf7<\/h3>\n<h4>&#xff08;1&#xff09;certbot\u5b89\u88c5<\/h4>\n<p>\u6211\u4eec\u9700\u8981\u5b89\u88c5Certbot\u5e76\u7528\u4e8e\u7533\u8bf7let\u2019s Encrypt \u3002 \u6253\u5f00\u7ec8\u7aef&#xff0c;\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p>sudo apt update<br \/>\nsudo apt install certbot python3-certbot-nginx<\/p>\n<h4>&#xff08;2&#xff09;let\u2019s Encrypt \u8bc1\u4e66\u7533\u8bf7<\/h4>\n<p> sudo certbot &#8211;nginx -d bak.sligenai.cn<\/p>\n<p>\u5982\u679c\u662f\u7b2c\u4e00\u6b21&#xff0c;\u53ef\u80fd\u4f1a\u8981\u4f60\u8f93\u5165\u4f60\u7684\u90ae\u7bb1\u548c\u8ba9\u4f60\u8f93\u5165A\u6216Yes\u540c\u610f\u4e00\u4e9b\u6761\u6b3e\u4f60\u6309\u7740\u8f93\u5165\u5c31\u884c\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092316-68021a048806b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u7136\u540e\u5c31\u751f\u6210\u597d\u8bc1\u4e66\u4e86\u3002\u8bb0\u5f97\u4fdd\u5b58\u597dfullchain.pem\u548cprivate.pem\u7684\u8def\u5f84&#xff0c;\u8fd9\u4e2a\u7b49\u4e0b\u4f1a\u7528\u5230\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u6211\u7684fullchain.pem\u548cprivate.pem\u7684\u8def\u5f84 \/etc\/letsencrypt\/live\/bak.sligenai.cn\/fullchain.pem \/etc\/letsencrypt\/live\/bak.sligenai.cn\/privkey.pem<\/p>\n<p>fullchain.pem\u548cprivkey.pem\u8fd9\u4e24\u4e2a\u6587\u4ef6\u5bf9\u4e8e\u914d\u7f6eWeb\u670d\u52a1\u5668\u4ee5\u5b89\u5168\u5730\u63d0\u4f9b\u670d\u52a1\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4e0b\u9762\u662f\u8fd9\u4e24\u4e2a\u6587\u4ef6\u7684\u8be6\u7ec6\u8bf4\u660e&#xff1a; fullchain.pem<\/p>\n<ul>\n<li>\u542b\u4e49&#xff1a;fullchain.pem\u6587\u4ef6\u5305\u542b\u4e86\u4f60\u7684\u57df\u540d\u8bc1\u4e66\u4ee5\u53ca\u4efb\u4f55\u4e2d\u95f4\u8bc1\u4e66\u7684\u5b8c\u6574\u94fe&#xff0c;\u4f46\u4e0d\u5305\u62ec\u6839\u8bc1\u4e66\u3002\u8fd9\u4e2a\u6587\u4ef6\u662f\u5c06\u4f60\u7684\u8bc1\u4e66(cert.pem)\u548c\u4e2d\u95f4\u8bc1\u4e66(chain.pem)\u5408\u5e76\u800c\u6210\u7684\u3002\u5728\u5927\u591a\u6570Web\u670d\u52a1\u5668\u7684SSL\u914d\u7f6e\u4e2d&#xff0c;\u4f7f\u7528\u8fd9\u4e2a\u6587\u4ef6\u53ef\u4ee5\u786e\u4fdd\u5ba2\u6237\u7aef&#xff08;\u5982Web\u6d4f\u89c8\u5668&#xff09;\u80fd\u591f\u4fe1\u4efb\u4f60\u7684\u8bc1\u4e66&#xff0c;\u5373\u80fd\u591f\u901a\u8fc7\u8bc1\u4e66\u94fe\u9a8c\u8bc1\u5230\u8fbe\u4e00\u4e2a\u6839CA&#xff0c;\u8be5\u6839CA\u5df2\u88ab\u5ba2\u6237\u7aef\u4fe1\u4efb\u3002<\/li>\n<li>\u7528\u9014&#xff1a;\u5728\u914d\u7f6eSSL\/TLS\u65f6&#xff0c;fullchain.pem\u901a\u5e38\u7528\u4e8e\u670d\u52a1\u5668\u914d\u7f6e\u4e2d\u6307\u5b9a\u8bc1\u4e66\u6587\u4ef6\u3002\u4f8b\u5982&#xff0c;\u5728Nginx\u4e2d&#xff0c;\u4f1a\u7528\u5b83\u6765\u8bbe\u7f6essl_certificate\u6307\u4ee4\u3002<\/li>\n<\/ul>\n<p>privkey.pem<\/p>\n<ul>\n<li>\u542b\u4e49&#xff1a;privkey.pem\u6587\u4ef6\u5305\u542b\u4e86\u4f60\u7684\u79c1\u94a5&#xff0c;\u8fd9\u662f\u5728\u751f\u6210CSR&#xff08;\u8bc1\u4e66\u7b7e\u540d\u8bf7\u6c42&#xff09;\u65f6\u521b\u5efa\u7684\u3002\u79c1\u94a5\u662f\u5b89\u5168\u901a\u4fe1\u7684\u57fa\u7840&#xff0c;\u7528\u4e8e\u5728SSL\/TLS\u63e1\u624b\u8fc7\u7a0b\u4e2d\u5bf9\u670d\u52a1\u5668\u7aef\u4fe1\u606f\u8fdb\u884c\u52a0\u5bc6&#xff0c;\u786e\u4fdd\u53ea\u6709\u5bf9\u5e94\u7684\u516c\u94a5&#xff08;\u5373\u4f60\u7684\u670d\u52a1\u5668\u8bc1\u4e66&#xff09;\u80fd\u591f\u89e3\u5bc6\u3002\u79c1\u94a5\u5fc5\u987b\u4fdd\u5bc6&#xff0c;\u4efb\u4f55\u6cc4\u9732\u90fd\u53ef\u80fd\u5bfc\u81f4\u901a\u4fe1\u88ab\u89e3\u5bc6\u3002<\/li>\n<li>\u7528\u9014&#xff1a;\u5728Web\u670d\u52a1\u5668\u7684SSL\u914d\u7f6e\u4e2d&#xff0c;privkey.pem\u7528\u4e8e\u8bbe\u7f6e\u79c1\u94a5\u6587\u4ef6\u7684\u4f4d\u7f6e\u3002\u4f8b\u5982&#xff0c;\u5728Nginx\u914d\u7f6e\u4e2d&#xff0c;\u4f1a\u7528\u5b83\u6765\u8bbe\u7f6essl_certificate_key\u6307\u4ee4\u3002<\/li>\n<\/ul>\n<p>\u603b\u7ed3<\/p>\n<ul>\n<li>fullchain.pem&#xff1a;\u5305\u542b\u4f60\u7684\u57df\u540d\u8bc1\u4e66\u548c\u4e2d\u95f4\u8bc1\u4e66\u7684\u5168\u90e8\u5185\u5bb9&#xff0c;\u7528\u4e8e\u670d\u52a1\u5668\u914d\u7f6e\u4e2d\u6307\u5b9a\u8bc1\u4e66\u94fe\u3002<\/li>\n<li>privkey.pem&#xff1a;\u5305\u542b\u4f60\u7684\u79c1\u94a5&#xff0c;\u7528\u4e8e\u670d\u52a1\u5668\u914d\u7f6e\u4e2d\u6307\u5b9a\u79c1\u94a5\u6587\u4ef6\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p>\u5728\u914d\u7f6eSSL\/TLS\u65f6&#xff0c;\u786e\u4fdd\u6b63\u786e\u4f7f\u7528\u8fd9\u4e9b\u6587\u4ef6&#xff0c;\u540c\u65f6\u4fdd\u62a4\u597d\u4f60\u7684\u79c1\u94a5&#xff0c;\u907f\u514d\u5b89\u5168\u98ce\u9669\u3002<\/p>\n<p>\u6ce81&#xff1a;\u5982\u679c\u4f60\u6ca1\u6709\u5f00\u653e443&#xff0c;80\u7aef\u53e3&#xff0c;\u7533\u8bf7\u7684\u65f6\u5019\u4f1a\u62a5\u9519 \u6ce82&#xff1a;\u5982\u679c\u4f60\u6ca1\u6709\u5c06\u57df\u540d\u89e3\u6790\u5230\u8fd9\u4e2a\u670d\u52a1\u5668\u7684ip\u4e5f\u4f1a\u62a5\u9519&#xff0c;\u4f1a\u51fa\u73b0\u7c7b\u4f3c\u4e0b\u9762\u7684\u56de\u590d\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092317-68021a0512f8b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h2>\u56db\u3001\u914d\u7f6enginx<\/h2>\n<h3>1\u3001nginx\u5b89\u88c5<\/h3>\n<p>sudo apt update<br \/>\nsudo apt install nginx<\/p>\n<h3>2\u3001\u914d\u7f6enginx.conf<\/h3>\n<p>\u6253\u5f00nginx.conf<\/p>\n<p> vim \/etc\/nginx\/nginx.conf<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2anginx.conf\u6a21\u7248<\/p>\n<p># nginx.conf<br \/>\nworker_processes auto; # \u4e0eworker_connections\u4e58\u79ef\u8868\u793a\u5b9e\u9645\u5904\u7406\u4e8b\u4ef6\u7684\u603b\u6570<\/p>\n<p>events {<br \/>\n    worker_connections 1024;  # \u6bcf\u4e2a\u5de5\u4f5c\u8fdb\u7a0b\u8fde\u63a5\u6570<br \/>\n}<\/p>\n<p>http {<br \/>\n    include       mime.types;   # \u6587\u4ef6\u6269\u5c55\u540d\u4e0e\u6587\u4ef6\u7c7b\u578b\u6620\u5c04\u8868<br \/>\n    default_type  application\/octet-stream;<br \/>\n    client_max_body_size 10M;<br \/>\n    sendfile        on;            # \u51cf\u5c11\u7f51\u7edc\u62a5\u6587\u6570\u91cf<br \/>\n    keepalive_timeout  65; # \u94fe\u63a5\u8d85\u65f6\u65f6\u95f4&#xff0c;\u81ea\u52a8\u65ad\u5f00&#xff0c;\u5982\u679c\u4e3a0\u5219\u65e0\u9650\u65f6\u957f\u3002<\/p>\n<p>    # HTTP server\u914d\u7f6e&#xff08;\u91cd\u5b9a\u5411\u5230HTTPS&#xff09;<br \/>\n    server {<br \/>\n        listen 80;  # \u76d1\u542c80\u7aef\u53e3<br \/>\n        server_name bak.sligenai.cn;             # \u66ff\u6362\u4e3a\u4f60\u7684\u57df\u540d<br \/>\n        return 301 https:\/\/$host$request_uri;  # \u5f3a\u5236\u91cd\u5b9a\u5411\u5230HTTPS<br \/>\n    }<br \/>\n    # HTTPS server\u914d\u7f6e<br \/>\n    server {<br \/>\n        listen 443 ssl;  # \u76d1\u542c443\u7aef\u53e3<br \/>\n        server_name bak.sligenai.cn;             # \u66ff\u6362\u4e3a\u4f60\u7684\u57df\u540d<\/p>\n<p>        ssl_certificate \/etc\/letsencrypt\/live\/bak.sligenai.cn\/fullchain.pem;          #\u66ff\u6362\u4e3a\u4f60\u7684fuuchian.pem<br \/>\n        ssl_certificate_key \/etc\/letsencrypt\/live\/bak.sligenai.cn\/privkey.pem;    #\u66ff\u6362\u4e3a\u4f60\u7684privkey.pem<\/p>\n<p>        root         \/usr\/share\/nginx\/html;<\/p>\n<p>        location \/ {<br \/>\n            index index.html index.htm;<br \/>\n            rewrite \/ \/login permanent; # \u6839\u636e\u9700\u6c42\u9009\u62e9\u662f\u5426\u4fdd\u7559<br \/>\n        }<\/p>\n<p>        location \/vue-test {                              #\u66ff\u6362\u4e3a\u4f60\u7684\u9879\u76ee\u8def\u7531&#xff0c;\u6ce8\u610f\u9700\u8981\u4e00\u5f00\u5934\u7684base\u4e00\u81f4<br \/>\n            index index.html index.htm;<br \/>\n            try_files $uri $uri\/ \/vue-test\/index.html;       #\u8fd9\u4e2a\u5219\u662f\/\u8def\u7531\/index.html \u524d\u9762\u7684\u90e8\u5206\u4e00\u81f4\u4e0d\u7528\u52a8\u3002<br \/>\n        }<\/p>\n<p>          location \/abc {   #\u66ff\u6362\u4e3a\u8bf7\u6c42\u62e6\u622a\u5668\u4e2d\u7684baseURL\u7684\u5730\u5740&#xff0c;\u5982\u679c\u6ca1\u6709\u540e\u7aef\u5219\u53ef\u4ee5\u5220\u6389\u8fd9\u4e00\u90e8\u5206<br \/>\n            add_header Cache-Control no-cache;<br \/>\n            add_header Pragma no-cache;<br \/>\n            add_header Expires 0;<br \/>\n            proxy_pass  http:\/\/localhost:3777\/;   #\u540e\u7aef\u5730\u5740<br \/>\n        }<br \/>\n        error_page  404  \/404.html;  # \u81ea\u5b9a\u4e49404\u9875\u9762<br \/>\n        location &#061; \/404.html {<br \/>\n            internal;<br \/>\n        }<\/p>\n<p>        error_page  500 502 503 504  \/50x.html;  # \u81ea\u5b9a\u4e49500\u9875\u9762<br \/>\n        location &#061; \/50x.html {<br \/>\n            internal;<br \/>\n        }<br \/>\n    }<\/p>\n<p>}<\/p>\n<p>\u6ce81&#xff1a;\u4e0a\u9762\u4e00\u5171\u4e24\u4e2a\u8def\u7531 \/vue-test\u3001 \/abc &#xff0c;\u5206\u522b\u4e3a\u524d\u7aef\u548c\u540e\u7aef\u3002 \u6ce82&#xff1a;\u5982\u679c\u6709\u591a\u4e2a\u9879\u76ee\u5219\u590d\u5236\/vue-test \u5728\u65c1\u8fb9\u7c98\u8d34\u4e00\u4e2a&#xff0c;\u6539\u6389\u8def\u7531\u5373\u53ef\u3002 \u6ce83&#xff1a; \u5982\u679c\u6709\u5176\u4ed6\u57df\u540d&#xff0c;\u5219\u989d\u5916\u628a\u4e0a\u9762\u8fd9\u4e2aserver\u590d\u5236\u4e00\u904d&#xff0c;\u5373\u53ef\u3002<\/p>\n<h3>3\u3001\u91cd\u65b0\u8fd0\u884cnginx<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092317-68021a056dc5f.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u68c0\u6d4bnginx.conf\u662f\u5426\u914d\u7f6e\u6b63\u5e38<\/p>\n<p>nginx -t<\/p>\n<p>\u5982\u679c\u62a5\u9519&#xff0c;\u5219\u6309\u7167\u63d0\u793a\u4fee\u6539\u5373\u53ef\u3002<\/p>\n<p>\u91cd\u65b0\u8fd0\u884cnginx<\/p>\n<p>sudo systemctl reload nginx<\/p>\n<h2>\u4e94\u3001\u8fd0\u884c\u6d4b\u8bd5<\/h2>\n<h3>1\u3001\u67e5\u770b\u8fd9\u4e2a\u670d\u52a1\u8f93\u51fa\u7684\u65e5\u5fd7<\/h3>\n<p>tail -f \/var\/log\/gunicorn_stderr.log<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092317-68021a057b5da.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u670d\u52a1\u6b63\u5e38\u3002<\/p>\n<h3>2\u3001\u8bbf\u95ee\u7f51\u7ad9<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092317-68021a05beb1e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u53ef\u4ee5\u770b\u5230\u540e\u7aef\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u3002 \u606d\u559c\u4f60&#xff0c;\u638c\u63e1\u4e86\u4f01\u4e1a\u7ea7 py\u540e\u7aef\u7684\u90e8\u7f72\u6b65\u9aa4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.6k\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf43\u6b21\u3002\u672a\u6765\u7684\u5f00\u53d1\u8005\u4eec\u8bf7\u4e0a\u5ea7\u3002FastAPI\uff1aFastAPI \u662f\u4e00\u4e2a\u73b0\u4ee3\u3001\u5feb\u901f\uff08\u9ad8\u6027\u80fd\uff09\u7684 web \u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa APIs\uff0c\u57fa\u4e8e Python 3.6+ \u7c7b\u578b\u63d0\u793a\u3002\u5feb\u901f\uff1a\u975e\u5e38\u9ad8\u7684\u6027\u80fd\uff0c\u63a5\u8fd1\u4e8e NodeJS \u548c Go\uff08\u7531 Starlette \u548c Pydantic \u63d0\u4f9b\uff09\u3002\u5feb\u901f\u7f16\u7801\uff1a\u63d0\u9ad8\u5f00\u53d1\u901f\u5ea6\u7ea6 200\uff05 \u81f3 300\uff05*\u3002\u5c11\u51fa\u9519\uff1a\u51cf\u5c11\u7ea6 40\uff05 \u7684\u4eba\u4e3a\uff08\u5f00\u53d1\u8005\uff09\u9519\u8bef\u3002\u76f4\u89c2\uff1a\u4f18\u79c0\u7684\u7f16\u8f91\u5668\u652f\u6301\uff0c\u2764\ufe0f \u7684\u5f00\u53d1\u4f53\u9a8c\u3002\u6613\u4e8e\u4f7f\u7528\uff1a\u8bbe\u8ba1\u6613\u4e8e\u4f7f\u7528\u548c\u5b66\u4e60\uff0c\u5c3d\u91cf\u51cf\u5c11\u5f00\u53d1\u65f6\u95f4\u3002_fastapi\u751f\u4ea7\u73af\u5883\u90e8\u7f72<\/p>\n","protected":false},"author":2,"featured_media":9360,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[318,72,317,316,43,44],"topic":[],"class_list":["post-9368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-ai","tag-fastapi","tag-python-","tag-316","tag-43","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09 - \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\/9368.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.6k\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf43\u6b21\u3002\u672a\u6765\u7684\u5f00\u53d1\u8005\u4eec\u8bf7\u4e0a\u5ea7\u3002FastAPI\uff1aFastAPI \u662f\u4e00\u4e2a\u73b0\u4ee3\u3001\u5feb\u901f\uff08\u9ad8\u6027\u80fd\uff09\u7684 web \u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa APIs\uff0c\u57fa\u4e8e Python 3.6+ \u7c7b\u578b\u63d0\u793a\u3002\u5feb\u901f\uff1a\u975e\u5e38\u9ad8\u7684\u6027\u80fd\uff0c\u63a5\u8fd1\u4e8e NodeJS \u548c Go\uff08\u7531 Starlette \u548c Pydantic \u63d0\u4f9b\uff09\u3002\u5feb\u901f\u7f16\u7801\uff1a\u63d0\u9ad8\u5f00\u53d1\u901f\u5ea6\u7ea6 200\uff05 \u81f3 300\uff05*\u3002\u5c11\u51fa\u9519\uff1a\u51cf\u5c11\u7ea6 40\uff05 \u7684\u4eba\u4e3a\uff08\u5f00\u53d1\u8005\uff09\u9519\u8bef\u3002\u76f4\u89c2\uff1a\u4f18\u79c0\u7684\u7f16\u8f91\u5668\u652f\u6301\uff0c\u2764\ufe0f \u7684\u5f00\u53d1\u4f53\u9a8c\u3002\u6613\u4e8e\u4f7f\u7528\uff1a\u8bbe\u8ba1\u6613\u4e8e\u4f7f\u7528\u548c\u5b66\u4e60\uff0c\u5c3d\u91cf\u51cf\u5c11\u5f00\u53d1\u65f6\u95f4\u3002_fastapi\u751f\u4ea7\u73af\u5883\u90e8\u7f72\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/9368.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T09:23:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092315-68021a03415ed.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=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/9368.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/9368.html\",\"name\":\"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T09:23:21+00:00\",\"dateModified\":\"2025-04-18T09:23:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/9368.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/9368.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/9368.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09\"}]},{\"@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":"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09 - \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\/9368.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb4.6k\u6b21\uff0c\u70b9\u8d5e10\u6b21\uff0c\u6536\u85cf43\u6b21\u3002\u672a\u6765\u7684\u5f00\u53d1\u8005\u4eec\u8bf7\u4e0a\u5ea7\u3002FastAPI\uff1aFastAPI \u662f\u4e00\u4e2a\u73b0\u4ee3\u3001\u5feb\u901f\uff08\u9ad8\u6027\u80fd\uff09\u7684 web \u6846\u67b6\uff0c\u7528\u4e8e\u6784\u5efa APIs\uff0c\u57fa\u4e8e Python 3.6+ \u7c7b\u578b\u63d0\u793a\u3002\u5feb\u901f\uff1a\u975e\u5e38\u9ad8\u7684\u6027\u80fd\uff0c\u63a5\u8fd1\u4e8e NodeJS \u548c Go\uff08\u7531 Starlette \u548c Pydantic \u63d0\u4f9b\uff09\u3002\u5feb\u901f\u7f16\u7801\uff1a\u63d0\u9ad8\u5f00\u53d1\u901f\u5ea6\u7ea6 200\uff05 \u81f3 300\uff05*\u3002\u5c11\u51fa\u9519\uff1a\u51cf\u5c11\u7ea6 40\uff05 \u7684\u4eba\u4e3a\uff08\u5f00\u53d1\u8005\uff09\u9519\u8bef\u3002\u76f4\u89c2\uff1a\u4f18\u79c0\u7684\u7f16\u8f91\u5668\u652f\u6301\uff0c\u2764\ufe0f \u7684\u5f00\u53d1\u4f53\u9a8c\u3002\u6613\u4e8e\u4f7f\u7528\uff1a\u8bbe\u8ba1\u6613\u4e8e\u4f7f\u7528\u548c\u5b66\u4e60\uff0c\u5c3d\u91cf\u51cf\u5c11\u5f00\u53d1\u65f6\u95f4\u3002_fastapi\u751f\u4ea7\u73af\u5883\u90e8\u7f72","og_url":"https:\/\/www.wsisp.com\/helps\/9368.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T09:23:21+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418092315-68021a03415ed.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/9368.html","url":"https:\/\/www.wsisp.com\/helps\/9368.html","name":"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T09:23:21+00:00","dateModified":"2025-04-18T09:23:21+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/9368.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/9368.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/9368.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5c06 FastAPI \u90e8\u7f72\u5230\u751f\u4ea7\u670d\u52a1\u5668\uff08\u4e00\u5957 \u5168\uff09"}]},{"@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\/9368","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=9368"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/9368\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/9360"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=9368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=9368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=9368"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=9368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}