{"id":11924,"date":"2025-04-18T19:03:49","date_gmt":"2025-04-18T11:03:49","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/11924.html"},"modified":"2025-04-18T19:03:49","modified_gmt":"2025-04-18T11:03:49","slug":"%e5%9c%a8-linux%e4%b8%8b%e4%bd%bf%e7%94%a8-python-3-11-%e5%92%8c-fastapi-%e6%90%ad%e5%bb%ba%e5%b8%a6%e5%85%8d%e8%b4%b9%e8%af%81%e4%b9%a6%e7%9a%84-https-%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/11924.html","title":{"rendered":"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668"},"content":{"rendered":"<p>\u5728\u5f53\u4eca\u6570\u5b57\u5316\u65f6\u4ee3&#xff0c;\u4fdd\u969c\u7f51\u7ad9\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002HTTPS \u534f\u8bae\u901a\u8fc7\u4f7f\u7528 SSL\/TLS \u52a0\u5bc6\u6280\u672f&#xff0c;\u80fd\u591f\u6709\u6548\u9632\u6b62\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u7a83\u53d6\u6216\u7be1\u6539\u3002\u672c\u6559\u7a0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 Ubuntu 22.04 \u7cfb\u7edf\u4e0a&#xff0c;\u4f7f\u7528 Python 3.11 \u548c FastAPI \u6846\u67b6\u642d\u5efa\u4e00\u4e2a\u5e26\u6709\u514d\u8d39 SSL \u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668\u3002<\/p>\n<h2>\u51c6\u5907\u5de5\u4f5c<\/h2>\n<p>\u5728\u5f00\u59cb\u4e4b\u524d&#xff0c;\u4f60\u9700\u8981\u786e\u4fdd\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u62e5\u6709\u4e00\u53f0\u8fd0\u884c Ubuntu 22.04 \u7684\u670d\u52a1\u5668\u3002<\/li>\n<li>\u5177\u5907\u4e00\u4e2a\u6709\u6548\u7684\u57df\u540d&#xff0c;\u5e76\u5c06\u5176 DNS \u89e3\u6790\u6307\u5411\u4f60\u7684\u670d\u52a1\u5668 IP \u5730\u5740\u3002\u56e0\u4e3a Let&#039;s Encrypt \u4e0d\u652f\u6301\u4e3a IP \u5730\u5740\u9881\u53d1\u8bc1\u4e66&#xff0c;\u6240\u4ee5\u57df\u540d\u662f\u5fc5\u9700\u7684\u3002<\/li>\n<li>\u670d\u52a1\u5668\u5df2\u7ecf\u8fde\u63a5\u5230\u4e92\u8054\u7f51&#xff0c;\u5e76\u4e14\u80fd\u591f\u6b63\u5e38\u8bbf\u95ee\u5916\u90e8\u7f51\u7edc\u3002<\/li>\n<\/ul>\n<h2>\u6b65\u9aa4 1&#xff1a;\u5b89\u88c5\u5fc5\u8981\u7684\u8f6f\u4ef6\u5305\u00a0<\/h2>\n<p>\u9996\u5148&#xff0c;\u6211\u4eec\u9700\u8981\u66f4\u65b0\u7cfb\u7edf\u7684\u8f6f\u4ef6\u5305\u5217\u8868&#xff0c;\u5e76\u5b89\u88c5 Python 3.11\u3001pip&#xff08;Python \u5305\u7ba1\u7406\u5de5\u5177&#xff09;\u3001Certbot&#xff08;\u7528\u4e8e\u83b7\u53d6\u514d\u8d39 SSL \u8bc1\u4e66&#xff09;\u548c Nginx&#xff08;\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668&#xff09;\u3002\u00a0<\/p>\n<p># \u66f4\u65b0\u7cfb\u7edf\u8f6f\u4ef6\u5305\u5217\u8868<br \/>\nsudo apt update<br \/>\n# \u5b89\u88c5 Python 3.11 \u548c pip<br \/>\nsudo apt install python3.11 python3.11-venv python3-pip<br \/>\n# \u5b89\u88c5 Certbot \u548c Nginx<br \/>\nsudo apt install certbot python3-certbot-nginx nginx <\/p>\n<p>\u00a0\u89e3\u91ca<\/p>\n<ul>\n<li>sudo apt update&#xff1a;\u8be5\u547d\u4ee4\u7528\u4e8e\u66f4\u65b0\u7cfb\u7edf\u8f6f\u4ef6\u5305\u5217\u8868&#xff0c;\u786e\u4fdd\u6211\u4eec\u80fd\u591f\u83b7\u53d6\u5230\u6700\u65b0\u7684\u8f6f\u4ef6\u5305\u4fe1\u606f\u3002<\/li>\n<li>sudo apt install python3.11 python3.11-venv python3-pip&#xff1a;\u5b89\u88c5 Python 3.11 \u53ca\u5176\u865a\u62df\u73af\u5883\u521b\u5efa\u5de5\u5177\u00a0venv\u00a0\u548c\u5305\u7ba1\u7406\u5de5\u5177\u00a0pip\u3002\u865a\u62df\u73af\u5883\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u9694\u79bb\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56&#xff0c;\u907f\u514d\u7248\u672c\u51b2\u7a81\u3002<\/li>\n<li>sudo apt install certbot python3-certbot-nginx nginx&#xff1a;\u5b89\u88c5 Certbot \u53ca\u5176 Nginx \u63d2\u4ef6&#xff0c;\u7528\u4e8e\u83b7\u53d6\u548c\u7ba1\u7406 Let&#039;s Encrypt \u514d\u8d39 SSL \u8bc1\u4e66&#xff0c;\u540c\u65f6\u5b89\u88c5 Nginx \u670d\u52a1\u5668\u3002<\/li>\n<\/ul>\n<h2>\u6b65\u9aa4 2&#xff1a;\u521b\u5efa Python \u865a\u62df\u73af\u5883\u5e76\u5b89\u88c5 FastAPI<\/h2>\n<p>\u4e3a\u4e86\u907f\u514d\u5168\u5c40 Python \u73af\u5883\u7684\u6c61\u67d3&#xff0c;\u6211\u4eec\u5c06\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883&#xff0c;\u5e76\u5728\u5176\u4e2d\u5b89\u88c5 FastAPI \u548c Uvicorn&#xff08;\u4e00\u4e2a\u7528\u4e8e\u8fd0\u884c FastAPI \u5e94\u7528\u7684 ASGI \u670d\u52a1\u5668&#xff09;\u3002<\/p>\n<p>\u00a0\u6ce8\u610f&#xff1a;\u4e5f\u53ef\u4ee5\u7528conda\u6765\u521b\u5efapyhton\u7684\u865a\u62df\u73af\u5883\u3002\u4ee5\u4e0b\u4ee3\u7801\u7528\u7684python3\u7684source\u6765\u521b\u5efa\u7684\u5efa\u8bae\u865a\u62df\u73af\u5883&#xff0c;\u4e5f\u591f\u7528\u3002<\/p>\n<p># \u521b\u5efa\u865a\u62df\u73af\u5883<br \/>\npython3.11 -m venv fastapi_env<br \/>\n# \u6fc0\u6d3b\u865a\u62df\u73af\u5883<br \/>\nsource fastapi_env\/bin\/activate<br \/>\n# \u5b89\u88c5 FastAPI \u548c Uvicorn<br \/>\npip install fastapi uvicorn <\/p>\n<p>\u89e3\u91ca<\/p>\n<ul>\n<li>python3.11 -m venv fastapi_env&#xff1a;\u4f7f\u7528 Python 3.11 \u7684\u00a0venv\u00a0\u6a21\u5757\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u00a0fastapi_env\u00a0\u7684\u865a\u62df\u73af\u5883\u3002<\/li>\n<li>source fastapi_env\/bin\/activate&#xff1a;\u6fc0\u6d3b\u865a\u62df\u73af\u5883&#xff0c;\u6fc0\u6d3b\u540e&#xff0c;\u6211\u4eec\u5728\u8be5\u7ec8\u7aef\u4e2d\u6267\u884c\u7684\u6240\u6709 Python \u547d\u4ee4\u90fd\u5c06\u4f7f\u7528\u8be5\u865a\u62df\u73af\u5883\u4e2d\u7684 Python \u548c\u76f8\u5173\u5305\u3002<\/li>\n<li>pip install fastapi uvicorn&#xff1a;\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5 FastAPI \u548c Uvicorn\u3002<\/li>\n<\/ul>\n<h2>\u6b65\u9aa4 3&#xff1a;\u7f16\u5199 FastAPI \u5e94\u7528<\/h2>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u00a0main.py\u00a0\u7684 Python \u6587\u4ef6&#xff0c;\u5e76\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684 FastAPI \u5e94\u7528\u3002<\/p>\n<p>from fastapi import FastAPI<\/p>\n<p>app &#061; FastAPI()<\/p>\n<p>&#064;app.get(&#034;\/&#034;)<br \/>\ndef read_root():<br \/>\n    return {&#034;&#8230;&#034;} <\/p>\n<p>\u00a0\u89e3\u91ca<\/p>\n<ul>\n<li>from fastapi import FastAPI&#xff1a;\u5bfc\u5165 FastAPI \u7c7b\u3002<\/li>\n<li>app &#061; FastAPI()&#xff1a;\u521b\u5efa\u4e00\u4e2a FastAPI \u5e94\u7528\u5b9e\u4f8b\u3002<\/li>\n<li>&#064;app.get(&#034;\/&#034;)&#xff1a;\u5b9a\u4e49\u4e00\u4e2a HTTP GET \u8bf7\u6c42\u5904\u7406\u51fd\u6570&#xff0c;\u5f53\u7528\u6237\u8bbf\u95ee\u6839\u8def\u5f84\u00a0\/\u00a0\u65f6&#xff0c;\u5c06\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u00a0{&#034;&#8230;&#034;}\u00a0\u7684 JSON \u54cd\u5e94\u3002<\/li>\n<\/ul>\n<h2>\u00a0\u6b65\u9aa4 4&#xff1a;\u914d\u7f6e Nginx \u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406<\/h2>\n<p>Nginx \u53ef\u4ee5\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668&#xff0c;\u5c06\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u8f6c\u53d1\u5230\u6211\u4eec\u7684 FastAPI \u5e94\u7528\u3002<\/p>\n<h3>\u00a04.1 \u521b\u5efa Nginx \u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Nginx \u914d\u7f6e\u6587\u4ef6\u00a0\/etc\/nginx\/sites-available\/fastapi_app\u3002<\/p>\n<p>sudo nano \/etc\/nginx\/sites-available\/fastapi_app <\/p>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9&#xff1a;\u00a0<\/p>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name your_domain;  # \u66ff\u6362\u4e3a\u4f60\u7684\u5b9e\u9645\u57df\u540d<\/p>\n<p>    location \/ {<br \/>\n        proxy_pass http:\/\/127.0.0.1:8000;<br \/>\n        proxy_set_header Host $host;<br \/>\n        proxy_set_header X-Real-IP $remote_addr;<br \/>\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\n        proxy_set_header X-Forwarded-Proto $scheme;<br \/>\n    }<br \/>\n} <\/p>\n<p>\u89e3\u91ca<\/p>\n<ul>\n<li>listen 80;&#xff1a;\u6307\u5b9a Nginx \u76d1\u542c HTTP \u7aef\u53e3 80\u3002<\/li>\n<li>server_name your_domain;&#xff1a;\u6307\u5b9a\u670d\u52a1\u5668\u7684\u57df\u540d&#xff0c;\u9700\u8981\u5c06\u00a0your_domain\u00a0\u66ff\u6362\u4e3a\u4f60\u81ea\u5df1\u7684\u57df\u540d\u3002<\/li>\n<li>proxy_pass http:\/\/127.0.0.1:8000;&#xff1a;\u5c06\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u8f6c\u53d1\u5230\u672c\u5730\u7684 8000 \u7aef\u53e3&#xff0c;\u5373\u6211\u4eec\u7684 FastAPI \u5e94\u7528\u8fd0\u884c\u7684\u7aef\u53e3\u3002<\/li>\n<li>proxy_set_header&#xff1a;\u8bbe\u7f6e\u4e00\u4e9b\u4ee3\u7406\u8bf7\u6c42\u5934&#xff0c;\u786e\u4fdd FastAPI \u5e94\u7528\u80fd\u591f\u83b7\u53d6\u5230\u5ba2\u6237\u7aef\u7684\u771f\u5b9e\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h3>4.2 \u521b\u5efa\u7b26\u53f7\u94fe\u63a5\u5e76\u6d4b\u8bd5\u914d\u7f6e<\/h3>\n<p>\u5c06\u914d\u7f6e\u6587\u4ef6\u94fe\u63a5\u5230\u00a0sites-enabled\u00a0\u76ee\u5f55&#xff0c;\u5e76\u6d4b\u8bd5 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u786e\u3002<\/p>\n<p># \u521b\u5efa\u7b26\u53f7\u94fe\u63a5\u5230 sites-enabled \u76ee\u5f55<br \/>\nsudo ln -s \/etc\/nginx\/sites-available\/fastapi_app \/etc\/nginx\/sites-enabled\/<br \/>\n# \u6d4b\u8bd5 Nginx \u914d\u7f6e<br \/>\nsudo nginx -t<br \/>\n# \u91cd\u542f Nginx \u670d\u52a1<br \/>\nsudo systemctl restart nginx <\/p>\n<h2>\u00a0\u6b65\u9aa4 5&#xff1a;\u83b7\u53d6\u514d\u8d39 SSL \u8bc1\u4e66<\/h2>\n<p>\u4f7f\u7528 Certbot \u5de5\u5177\u83b7\u53d6 Let&#039;s Encrypt \u514d\u8d39 SSL \u8bc1\u4e66\u3002<\/p>\n<p>sudo certbot &#8211;nginx -d your_domain  # \u66ff\u6362\u4e3a\u4f60\u7684\u5b9e\u9645\u57df\u540d <\/p>\n<p>\u591a\u4e2a\u57df\u540d\u65f6&#xff0c;\u7533\u8bf7\u65b9\u6cd5\u5982\u4e0b&#xff1a;\u00a0<\/p>\n<p>sudo certbot &#8211;nginx -d your_domain.com -d www.your_domain.com <\/p>\n<p>\u8be6\u7ec6\u63d0\u793a\u548c\u8f93\u5165\u8bf4\u660e<\/p>\n<h3>5.1 \u90ae\u7bb1\u5730\u5740\u8f93\u5165<\/h3>\n<p>Saving debug log to \/var\/log\/letsencrypt\/letsencrypt.log<br \/>\nPlugins selected: Authenticator nginx, Installer nginx<br \/>\nEnter email address (used for urgent renewal and security notices) (Enter &#039;c&#039; to<br \/>\ncancel): <\/p>\n<p>Let&#039;s Encrypt \u9700\u8981\u4e00\u4e2a\u6709\u6548\u7684\u90ae\u7bb1\u5730\u5740&#xff0c;\u7528\u4e8e\u5728\u8bc1\u4e66\u5373\u5c06\u5230\u671f\u6216\u6709\u5b89\u5168\u901a\u77e5\u65f6\u8054\u7cfb\u4f60\u3002\u8f93\u5165\u4f60\u7684\u5e38\u7528\u90ae\u7bb1\u5730\u5740&#xff0c;\u7136\u540e\u6309\u56de\u8f66\u952e\u3002<\/p>\n<h3>5.2 \u534f\u8bae\u6761\u6b3e\u786e\u8ba4<\/h3>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nPlease read the Terms of Service at<br \/>\nhttps:\/\/letsencrypt.org\/documents\/LE-SA-v1.2-November-15-2017.pdf. You must<br \/>\nagree in order to register with the ACME server. Do you agree?<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\n(Y)es\/(N)o: <\/p>\n<p>\u4f60\u9700\u8981\u540c\u610f Let&#039;s Encrypt \u7684\u670d\u52a1\u6761\u6b3e\u624d\u80fd\u7ee7\u7eed\u6ce8\u518c\u5e76\u83b7\u53d6\u8bc1\u4e66\u3002\u8f93\u5165\u00a0Y\u00a0\u7136\u540e\u6309\u56de\u8f66\u952e\u8868\u793a\u540c\u610f\u3002<\/p>\n<h3>5.3 \u8ba2\u9605\u90ae\u4ef6\u9009\u9879<\/h3>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nWould you be willing to share your email address with the Electronic Frontier<br \/>\nFoundation, a founding partner of the Let&#039;s Encrypt project and the non-profit<br \/>\norganization that develops Certbot? We&#039;d like to send you email about our work<br \/>\nencrypting the web, EFF news, campaigns, and ways to support digital freedom.<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\n(Y)es\/(N)o: <\/p>\n<p>\u00a0\u8fd9\u662f\u4e00\u4e2a\u53ef\u9009\u7684\u8ba2\u9605\u9009\u9879&#xff0c;\u8be2\u95ee\u4f60\u662f\u5426\u613f\u610f\u4e0e\u7535\u5b50\u524d\u6cbf\u57fa\u91d1\u4f1a&#xff08;EFF&#xff09;\u5171\u4eab\u4f60\u7684\u90ae\u7bb1\u5730\u5740&#xff0c;\u4ee5\u4fbf\u63a5\u6536\u4ed6\u4eec\u7684\u76f8\u5173\u65b0\u95fb\u548c\u6d3b\u52a8\u4fe1\u606f\u3002\u5982\u679c\u4f60\u613f\u610f\u63a5\u6536\u76f8\u5173\u90ae\u4ef6&#xff0c;\u8f93\u5165\u00a0Y\u00a0\u5e76\u56de\u8f66&#xff1b;\u5982\u679c\u4e0d\u613f\u610f&#xff0c;\u8f93\u5165\u00a0N\u00a0\u5e76\u56de\u8f66\u3002<\/p>\n<h3>5.4 \u57df\u540d\u9a8c\u8bc1\u4e0e\u8bc1\u4e66\u5b89\u88c5\u786e\u8ba4<\/h3>\n<p>Obtaining a new certificate<br \/>\nPerforming the following challenges:<br \/>\nhttp-01 challenge for your_domain<br \/>\nWaiting for verification&#8230;<br \/>\nCleaning up challenges<br \/>\nDeploying Certificate to VirtualHost \/etc\/nginx\/sites-enabled\/fastapi_app<\/p>\n<p>Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\n1: No redirect &#8211; Make no further changes to the webserver configuration.<br \/>\n2: Redirect &#8211; Make all requests redirect to secure HTTPS access. Choose this for<br \/>\nnew sites, or if you&#039;re confident your site works on HTTPS. You can undo this<br \/>\nchange by editing your web server&#039;s configuration.<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nSelect the appropriate number [1-2] then [enter] (press &#039;c&#039; to cancel): <\/p>\n<p>\u00a0Certbot \u4f1a\u9a8c\u8bc1\u4f60\u7684\u57df\u540d\u6240\u6709\u6743&#xff0c;\u5e76\u5728\u9a8c\u8bc1\u901a\u8fc7\u540e\u90e8\u7f72\u8bc1\u4e66\u3002\u8fd9\u91cc\u4f1a\u8be2\u95ee\u4f60\u662f\u5426\u8981\u5c06\u6240\u6709 HTTP \u8bf7\u6c42\u91cd\u5b9a\u5411\u5230 HTTPS\u3002<\/p>\n<ul>\n<li>\u5982\u679c\u4f60\u5e0c\u671b\u5c06\u6240\u6709 HTTP \u8bf7\u6c42\u91cd\u5b9a\u5411\u5230 HTTPS&#xff0c;\u8f93\u5165\u00a02\u00a0\u5e76\u56de\u8f66\u3002<\/li>\n<li>\u5982\u679c\u4f60\u6682\u65f6\u4e0d\u60f3\u8fdb\u884c\u91cd\u5b9a\u5411&#xff0c;\u8f93\u5165\u00a01\u00a0\u5e76\u56de\u8f66\u3002<\/li>\n<\/ul>\n<h3>5.5 \u5b8c\u6210\u63d0\u793a<\/h3>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nPlease read the Terms of Service at<br \/>\nhttps:\/\/letsencrypt.org\/documents\/LE-SA-v1.5-February-24-2025.pdf. You must<br \/>\nagree in order to register with the ACME server. Do you agree?<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\n(Y)es\/(N)o: Y<\/p>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nWould you be willing, once your first certificate is successfully issued, to<br \/>\nshare your email address with the Electronic Frontier Foundation, a founding<br \/>\npartner of the Let&#039;s Encrypt project and the non-profit organization that<br \/>\ndevelops Certbot? We&#039;d like to send you email about our work encrypting the web,<br \/>\nEFF news, campaigns, and ways to support digital freedom.<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\n(Y)es\/(N)o: Y<br \/>\nAccount registered.<br \/>\nRequesting a certificate for ftpeak.com<\/p>\n<p>Successfully received certificate.<br \/>\nCertificate is saved at: \/etc\/letsencrypt\/live\/ftpeak.com\/fullchain.pem<br \/>\nKey is saved at:         \/etc\/letsencrypt\/live\/ftpeak.com\/privkey.pem<br \/>\nThis certificate expires on 2025-06-15.<br \/>\nThese files will be updated when the certificate renews.<br \/>\nCertbot has set up a scheduled task to automatically renew this certificate in the background.<\/p>\n<p>Deploying certificate<br \/>\nSuccessfully deployed certificate for ftpeak.com to \/etc\/nginx\/sites-enabled\/fastapi_app<br \/>\nCongratulations! You have successfully enabled HTTPS on https:\/\/ftpeak.com<\/p>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nIf you like Certbot, please consider supporting our work by:<br \/>\n * Donating to ISRG \/ Let&#039;s Encrypt:   https:\/\/letsencrypt.org\/donate<br \/>\n * Donating to EFF:                    https:\/\/eff.org\/donate-le<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<\/p>\n<p>\u8fd9\u8868\u793a\u8bc1\u4e66\u5df2\u7ecf\u6210\u529f\u83b7\u53d6\u5e76\u5b89\u88c5&#xff0c;\u540c\u65f6\u4f1a\u663e\u793a\u8bc1\u4e66\u548c\u79c1\u94a5\u7684\u4fdd\u5b58\u8def\u5f84\u4ee5\u53ca\u8bc1\u4e66\u7684\u5230\u671f\u65e5\u671f\u7b49\u91cd\u8981\u4fe1\u606f\u3002<\/p>\n<h2 style=\"background-color:transparent\">\u6b65\u9aa4 6&#xff1a;\u5728\u914d\u7f6e\u4e2d\u589e\u52a0SSL<\/h2>\n<h3>6.1 \u7f16\u8f91\u914d\u7f6e\u6587\u4ef6<\/h3>\n<p>\u6253\u5f00\u914d\u7f6e\u6587\u4ef6\u8fdb\u5165\u7f16\u8f91\u72b6\u6001&#xff1a;<\/p>\n<p>sudo nano \/etc\/nginx\/sites-available\/fastapi_app <\/p>\n<p>\u00a0\u4ee3\u7801\u4fee\u6539\u5982\u4e0b&#xff1a;<\/p>\n<p># HTTP \u670d\u52a1\u5668\u5757&#xff0c;\u7528\u4e8e\u5c06\u6240\u6709 HTTP \u8bf7\u6c42\u91cd\u5b9a\u5411\u5230 HTTPS<br \/>\nserver {<br \/>\n    listen 80;<br \/>\n    server_name ftpeak.com;<br \/>\n    # \u6c38\u4e45\u91cd\u5b9a\u5411 HTTP \u8bf7\u6c42\u5230 HTTPS<br \/>\n    return 301 https:\/\/$host$request_uri;<br \/>\n}<\/p>\n<p># HTTPS \u670d\u52a1\u5668\u5757&#xff0c;\u5904\u7406\u5b9e\u9645\u7684 HTTPS \u8bf7\u6c42<br \/>\nserver {<br \/>\n    listen 443 ssl;<br \/>\n    server_name ftpeak.com;<\/p>\n<p>    # SSL \u8bc1\u4e66\u548c\u79c1\u94a5\u914d\u7f6e<br \/>\n    ssl_certificate \/etc\/letsencrypt\/live\/ftpeak.com\/fullchain.pem;<br \/>\n    ssl_certificate_key \/etc\/letsencrypt\/live\/ftpeak.com\/privkey.pem;<\/p>\n<p>    # \u5305\u542b Certbot \u63d0\u4f9b\u7684 SSL \u914d\u7f6e\u9009\u9879<br \/>\n    include \/etc\/letsencrypt\/options-ssl-nginx.conf;<br \/>\n    # SSL  Diffie-Hellman \u53c2\u6570\u914d\u7f6e<br \/>\n    ssl_dhparam \/etc\/letsencrypt\/ssl-dhparams.pem;<\/p>\n<p>    # \u53cd\u5411\u4ee3\u7406\u914d\u7f6e&#xff0c;\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u672c\u5730\u7684 FastAPI \u5e94\u7528<br \/>\n    location \/ {<br \/>\n        proxy_pass http:\/\/127.0.0.1:8000;<br \/>\n        proxy_set_header Host $host;<br \/>\n        proxy_set_header X-Real-IP $remote_addr;<br \/>\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\n        proxy_set_header X-Forwarded-Proto $scheme;<br \/>\n    }<br \/>\n} <\/p>\n<h3 style=\"background-color:transparent\">6.1 \u542f\u52a8 FastAPI \u5e94\u7528<\/h3>\n<p>\u5728\u6fc0\u6d3b\u7684\u865a\u62df\u73af\u5883\u4e2d\u542f\u52a8 FastAPI \u5e94\u7528\u3002<\/p>\n<p>uvicorn main:app &#8211;host 127.0.0.1 &#8211;port 8000 <\/p>\n<p>\u89e3\u91ca<\/p>\n<ul>\n<li>uvicorn main:app&#xff1a;\u6307\u5b9a\u8981\u8fd0\u884c\u7684 FastAPI \u5e94\u7528&#xff0c;main\u00a0\u662f Python \u6587\u4ef6\u540d&#xff0c;app\u00a0\u662f FastAPI \u5e94\u7528\u5b9e\u4f8b\u7684\u540d\u79f0\u3002<\/li>\n<li>&#8211;host 127.0.0.1&#xff1a;\u6307\u5b9a\u5e94\u7528\u76d1\u542c\u7684 IP \u5730\u5740\u4e3a\u672c\u5730\u56de\u73af\u5730\u5740\u3002<\/li>\n<li>&#8211;port 8000&#xff1a;\u6307\u5b9a\u5e94\u7528\u76d1\u542c\u7684\u7aef\u53e3\u4e3a 8000\u3002<\/li>\n<\/ul>\n<h2>\u6b65\u9aa4 7&#xff1a;\u9a8c\u8bc1 HTTPS \u8bbf\u95ee<\/h2>\n<p>\u73b0\u5728&#xff0c;\u4f60\u53ef\u4ee5\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u00a0https:\/\/your_domain&#xff08;\u66ff\u6362\u4e3a\u4f60\u7684\u5b9e\u9645\u57df\u540d&#xff09;\u6765\u9a8c\u8bc1 HTTPS \u670d\u52a1\u5668\u662f\u5426\u6b63\u5e38\u5de5\u4f5c\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38&#xff0c;\u4f60\u5e94\u8be5\u80fd\u770b\u5230\u00a0{&#034;&#8230;&#034;}\u00a0\u7684\u54cd\u5e94\u3002<\/p>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ul>\n<li>\u786e\u4fdd\u670d\u52a1\u5668\u7684\u9632\u706b\u5899\u5141\u8bb8 HTTP&#xff08;\u7aef\u53e3 80&#xff09;\u548c HTTPS&#xff08;\u7aef\u53e3 443&#xff09;\u6d41\u91cf\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5f00\u653e\u7aef\u53e3&#xff1a;\u00a0<\/li>\n<\/ul>\n<p>sudo ufw allow 80<br \/>\nsudo ufw allow 443<br \/>\nsudo ufw allow 443<\/p>\n<h2>\u6b65\u9aa48&#xff1a;\u81ea\u52a8\u66f4\u65b0\u8bc1\u4e66<\/h2>\n<h3>\u81ea\u52a8\u66f4\u65b0\u6d4b\u8bd5<\/h3>\n<p>Let&#039;s Encrypt \u8bc1\u4e66\u7684\u6709\u6548\u671f\u4e3a 90 \u5929&#xff0c;\u4e3a\u4e86\u907f\u514d\u8bc1\u4e66\u8fc7\u671f\u5bfc\u81f4\u670d\u52a1\u4e2d\u65ad&#xff0c;\u5efa\u8bae\u8bbe\u7f6e\u5b9a\u671f\u81ea\u52a8\u66f4\u65b0\u8bc1\u4e66\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6d4b\u8bd5\u81ea\u52a8\u66f4\u65b0&#xff1a;<\/p>\n<p>sudo certbot renew &#8211;dry-run <\/p>\n<p>\u6d4b\u8bd5\u7ed3\u679c\u5982\u679c\u901a\u8fc7\u5982\u4e0b&#xff1a;<\/p>\n<p>Saving debug log to \/var\/log\/letsencrypt\/letsencrypt.log<\/p>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nProcessing \/etc\/letsencrypt\/renewal\/ftpeak.com.conf<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nAccount registered.<br \/>\nSimulating renewal of an existing certificate for ftpeak.com<\/p>\n<p>&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<br \/>\nCongratulations, all simulated renewals succeeded:<br \/>\n  \/etc\/letsencrypt\/live\/ftpeak.com\/fullchain.pem (success)<br \/>\n&#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211; &#8211;<\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u7cfb\u7edf\u7684\u5b9a\u65f6\u4efb\u52a1&#xff08;\u5982\u00a0crontab -e&#xff09;\u6765\u5b9a\u671f\u6267\u884c\u00a0certbot renew\u00a0\u547d\u4ee4\u3002<\/p>\n<p>crontab -e <\/p>\n<p>\u00a0\u5982\u679c\u4f60\u662f\u7b2c\u4e00\u6b21\u4f7f\u7528\u8be5\u547d\u4ee4&#xff0c;\u7cfb\u7edf\u53ef\u80fd\u4f1a\u63d0\u793a\u4f60\u9009\u62e9\u4e00\u4e2a\u6587\u672c\u7f16\u8f91\u5668&#xff0c;\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u559c\u597d\u9009\u62e9&#xff0c;\u4f8b\u5982\u9009\u62e9\u00a0nano\u00a0\u7f16\u8f91\u5668&#xff0c;\u8f93\u5165\u5bf9\u5e94\u7684\u6570\u5b57\u5e76\u56de\u8f66\u5373\u53ef\u3002<\/p>\n<h3>\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1<\/h3>\n<p>\u5728\u6253\u5f00\u7684\u00a0crontab\u00a0\u6587\u4ef6\u4e2d&#xff0c;\u6dfb\u52a0\u5982\u4e0b\u4e00\u884c\u5185\u5bb9&#xff1a;<\/p>\n<p>0 2 * * 1 \/usr\/bin\/certbot renew &#8211;quiet &#8211;deploy-hook &#034;systemctl reload nginx&#034; <\/p>\n<p>\u4ee3\u7801\u89e3\u91ca<\/p>\n<ul>\n<li>\n<p>\u65f6\u95f4\u8bbe\u7f6e\u90e8\u5206&#xff08;0 2 * * 1&#xff09;&#xff1a;<\/p>\n<ul>\n<li>0\u00a0\u8868\u793a\u5206\u949f&#xff0c;\u5373\u6bcf\u5c0f\u65f6\u7684\u7b2c 0 \u5206\u949f&#xff08;\u6574\u70b9&#xff09;\u3002<\/li>\n<li>2\u00a0\u8868\u793a\u5c0f\u65f6&#xff0c;\u5373\u51cc\u6668 2 \u70b9\u3002<\/li>\n<li>*\u00a0\u8868\u793a\u4efb\u610f\u503c&#xff0c;\u8fd9\u91cc\u524d\u4e24\u4e2a\u00a0*\u00a0\u5206\u522b\u8868\u793a\u6bcf\u6708\u7684\u4efb\u610f\u5929\u548c\u6bcf\u5e74\u7684\u4efb\u610f\u6708\u3002<\/li>\n<li>1\u00a0\u8868\u793a\u661f\u671f&#xff0c;\u5373\u661f\u671f\u4e00\u3002<\/li>\n<\/ul>\n<p>\u7efc\u5408\u8d77\u6765&#xff0c;0 2 * * 1\u00a0\u8868\u793a\u6bcf\u5468\u4e00\u51cc\u6668 2 \u70b9\u6267\u884c\u8be5\u4efb\u52a1\u3002\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u8c03\u6574\u65f6\u95f4&#xff0c;\u4f8b\u5982\u4f60\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u6bcf\u6708\u6267\u884c\u4e00\u6b21&#xff0c;\u5c06\u65f6\u95f4\u8bbe\u7f6e\u4e3a\u00a00 2 1 * *\u00a0&#xff0c;\u8868\u793a\u6bcf\u6708 1 \u53f7\u51cc\u6668 2 \u70b9\u6267\u884c\u3002<\/p>\n<\/li>\n<li>\n<p>\u547d\u4ee4\u90e8\u5206&#xff08;\/usr\/bin\/certbot renew &#8211;quiet &#8211;deploy-hook &#034;systemctl reload nginx&#034;&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\/usr\/bin\/certbot renew&#xff1a;\u8fd9\u662f\u6267\u884c Certbot \u8bc1\u4e66\u66f4\u65b0\u7684\u547d\u4ee4\u3002<\/li>\n<li>&#8211;quiet&#xff1a;\u8868\u793a\u4ee5\u5b89\u9759\u6a21\u5f0f\u8fd0\u884c&#xff0c;\u907f\u514d\u5728\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u8f93\u51fa\u8fc7\u591a\u7684\u4fe1\u606f&#xff0c;\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u5e72\u6270\u3002<\/li>\n<li>&#8211;deploy-hook &#034;systemctl reload nginx&#034;&#xff1a;\u8fd9\u662f\u4e00\u4e2a\u90e8\u7f72\u94a9\u5b50\u9009\u9879&#xff0c;\u5f53 Certbot \u6210\u529f\u66f4\u65b0\u8bc1\u4e66\u540e&#xff0c;\u4f1a\u6267\u884c\u53cc\u5f15\u53f7\u5185\u7684\u547d\u4ee4\u3002\u8fd9\u91cc\u7684\u00a0systemctl reload nginx\u00a0\u8868\u793a\u91cd\u65b0\u52a0\u8f7d Nginx \u670d\u52a1&#xff0c;\u4f7f\u65b0\u7684\u8bc1\u4e66\u914d\u7f6e\u751f\u6548\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>\u4fdd\u5b58\u5e76\u9000\u51fa<\/h3>\n<p>\u5728\u00a0nano\u00a0\u7f16\u8f91\u5668\u4e2d&#xff0c;\u6309\u4e0b\u00a0Ctrl &#043; X\u00a0\u7ec4\u5408\u952e&#xff0c;\u7136\u540e\u8f93\u5165\u00a0Y\u00a0\u786e\u8ba4\u4fdd\u5b58\u4fee\u6539&#xff0c;\u6700\u540e\u6309\u4e0b\u56de\u8f66\u952e\u9000\u51fa\u7f16\u8f91\u5668\u3002\u00a0<\/p>\n<h3>\u5217\u51fa\u4f60\u8bbe\u7f6e\u7684\u5b9a\u65f6\u4efb\u52a1<\/h3>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u5f53\u524d\u7528\u6237\u7684\u00a0crontab\u00a0\u4efb\u52a1\u5217\u8868&#xff0c;\u786e\u8ba4\u521a\u624d\u6dfb\u52a0\u7684\u4efb\u52a1\u662f\u5426\u5df2\u7ecf\u6b63\u786e\u4fdd\u5b58&#xff1a;<\/p>\n<p>crontab -l <\/p>\n<p>\u5982\u679c\u8f93\u51fa\u4e2d\u5305\u542b\u4f60\u6dfb\u52a0\u7684\u5b9a\u65f6\u4efb\u52a1&#xff0c;\u8bf4\u660e\u914d\u7f6e\u6210\u529f\u3002\u4e4b\u540e&#xff0c;\u7cfb\u7edf\u4f1a\u6309\u7167\u4f60\u8bbe\u7f6e\u7684\u65f6\u95f4\u5b9a\u671f\u6267\u884c\u8bc1\u4e66\u66f4\u65b0\u64cd\u4f5c\u3002<\/p>\n<h3>\u6ce8\u610f\u4e8b\u9879<\/h3>\n<ul>\n<li>\u786e\u4fdd\u00a0certbot\u00a0\u547d\u4ee4\u7684\u8def\u5f84\u00a0\/usr\/bin\/certbot\u00a0\u662f\u6b63\u786e\u7684\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u00a0which certbot\u00a0\u547d\u4ee4\u6765\u786e\u8ba4\u5176\u5b9e\u9645\u8def\u5f84\u3002<\/li>\n<li>\u5728\u4f7f\u7528\u00a0systemctl reload nginx\u00a0\u4e4b\u524d&#xff0c;\u8981\u786e\u4fdd\u5f53\u524d\u7528\u6237\u6709\u8db3\u591f\u7684\u6743\u9650\u6765\u6267\u884c\u8be5\u547d\u4ee4\u3002\u5982\u679c\u9047\u5230\u6743\u9650\u95ee\u9898&#xff0c;\u53ef\u80fd\u9700\u8981\u8c03\u6574\u00a0sudo\u00a0\u914d\u7f6e\u6216\u4f7f\u7528\u5176\u4ed6\u65b9\u5f0f\u6765\u91cd\u65b0\u52a0\u8f7d Nginx \u670d\u52a1\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u5728\u5f53\u4eca\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u4fdd\u969c\u7f51\u7ad9\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002HTTPS \u534f\u8bae\u901a\u8fc7\u4f7f\u7528 SSL\/TLS \u52a0\u5bc6\u6280\u672f\uff0c\u80fd\u591f\u6709\u6548\u9632\u6b62\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u7a83\u53d6\u6216\u7be1\u6539\u3002\u672c\u6559\u7a0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 Ubuntu 22.04 \u7cfb\u7edf\u4e0a\uff0c\u4f7f\u7528 Python 3.11 \u548c FastAPI \u6846\u67b6\u642d\u5efa\u4e00\u4e2a\u5e26\u6709\u514d\u8d39 SSL \u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668\u3002_fastapi \u5982\u4f55\u914d\u7f6essl<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[72,622,81,494,103],"topic":[],"class_list":["post-11924","post","type-post","status-publish","format-standard","hentry","category-server","tag-fastapi","tag-https","tag-python","tag-python3-11","tag-ubuntu"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668 - \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\/11924.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u5728\u5f53\u4eca\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u4fdd\u969c\u7f51\u7ad9\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002HTTPS \u534f\u8bae\u901a\u8fc7\u4f7f\u7528 SSL\/TLS \u52a0\u5bc6\u6280\u672f\uff0c\u80fd\u591f\u6709\u6548\u9632\u6b62\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u7a83\u53d6\u6216\u7be1\u6539\u3002\u672c\u6559\u7a0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 Ubuntu 22.04 \u7cfb\u7edf\u4e0a\uff0c\u4f7f\u7528 Python 3.11 \u548c FastAPI \u6846\u67b6\u642d\u5efa\u4e00\u4e2a\u5e26\u6709\u514d\u8d39 SSL \u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668\u3002_fastapi \u5982\u4f55\u914d\u7f6essl\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/11924.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-18T11:03:49+00:00\" \/>\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=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11924.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/11924.html\",\"name\":\"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T11:03:49+00:00\",\"dateModified\":\"2025-04-18T11:03:49+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/11924.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/11924.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/11924.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668\"}]},{\"@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":"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668 - \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\/11924.html","og_locale":"zh_CN","og_type":"article","og_title":"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.4k\u6b21\uff0c\u70b9\u8d5e34\u6b21\uff0c\u6536\u85cf23\u6b21\u3002\u5728\u5f53\u4eca\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u4fdd\u969c\u7f51\u7ad9\u6570\u636e\u4f20\u8f93\u7684\u5b89\u5168\u6027\u81f3\u5173\u91cd\u8981\u3002HTTPS \u534f\u8bae\u901a\u8fc7\u4f7f\u7528 SSL\/TLS \u52a0\u5bc6\u6280\u672f\uff0c\u80fd\u591f\u6709\u6548\u9632\u6b62\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u88ab\u7a83\u53d6\u6216\u7be1\u6539\u3002\u672c\u6559\u7a0b\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728 Ubuntu 22.04 \u7cfb\u7edf\u4e0a\uff0c\u4f7f\u7528 Python 3.11 \u548c FastAPI \u6846\u67b6\u642d\u5efa\u4e00\u4e2a\u5e26\u6709\u514d\u8d39 SSL \u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668\u3002_fastapi \u5982\u4f55\u914d\u7f6essl","og_url":"https:\/\/www.wsisp.com\/helps\/11924.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T11:03:49+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/11924.html","url":"https:\/\/www.wsisp.com\/helps\/11924.html","name":"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T11:03:49+00:00","dateModified":"2025-04-18T11:03:49+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/11924.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/11924.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/11924.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u5728 Linux\u4e0b\u4f7f\u7528 Python 3.11 \u548c FastAPI \u642d\u5efa\u5e26\u514d\u8d39\u8bc1\u4e66\u7684 HTTPS \u670d\u52a1\u5668"}]},{"@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\/11924","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=11924"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/11924\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=11924"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=11924"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=11924"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=11924"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}