{"id":62421,"date":"2025-04-29T14:44:01","date_gmt":"2025-04-29T06:44:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/62421\/"},"modified":"2025-04-29T14:44:01","modified_gmt":"2025-04-29T06:44:01","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8linux%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8a%e5%ae%9e%e6%96%bd%e5%bc%ba%e5%a4%a7%e7%9a%84web%e6%8e%a5%e5%8f%a3%e5%ae%89%e5%85%a8%e6%80%a7%e7%ad%96%e7%95%a5%ef%bc%9f-3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/62421\/","title":{"rendered":"\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u5b9e\u65bd\u5f3a\u5927\u7684Web\u63a5\u53e3\u5b89\u5168\u6027\u7b56\u7565\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169415824469640.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u5b9e\u65bd\u5f3a\u5927\u7684Web\u63a5\u53e3\u5b89\u5168\u6027\u7b56\u7565\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u5b9e\u65bd\u5f3a\u5927\u7684Web\u63a5\u53e3\u5b89\u5168\u6027\u7b56\u7565\uff1f\u63d2\u56fe\" \/><\/p>\n<p>\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u5b9e\u65bd\u5f3a\u5927\u7684Web\u63a5\u53e3\u5b89\u5168\u6027\u7b56\u7565\uff1f<\/p>\n<p>\u6982\u8ff0\uff1a<br \/>\u968f\u7740\u4e92\u8054\u7f51\u7684\u5feb\u901f\u53d1\u5c55\uff0cWeb\u5e94\u7528\u6210\u4e3a\u4e86\u4f17\u591a\u4f01\u4e1a\u548c\u4e2a\u4eba\u8fdb\u884c\u4e1a\u52a1\u4ea4\u4e92\u7684\u9996\u9009\u65b9\u5f0f\u3002\u7136\u800c\uff0c\u968f\u4e4b\u800c\u6765\u7684\u662fWeb\u63a5\u53e3\u5b89\u5168\u6027\u7684\u5a01\u80c1\u4e5f\u6025\u5267\u589e\u52a0\u3002\u4e3a\u4e86\u4fdd\u62a4Web\u5e94\u7528\u7684\u5b89\u5168\u6027\uff0cLinux\u670d\u52a1\u5668\u4e0a\u7684Web\u63a5\u53e3\u9700\u8981\u5b9e\u65bd\u5f3a\u5927\u7684\u5b89\u5168\u6027\u7b56\u7565\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e00\u4e9b\u6709\u6548\u7684\u65b9\u6cd5\u6765\u63d0\u5347Web\u63a5\u53e3\u7684\u5b89\u5168\u6027\uff0c\u5e76\u9644\u4e0a\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<ol>\n<li>\u4f7f\u7528HTTPS\u52a0\u5bc6\u901a\u4fe1<br \/>\u5728\u8bbe\u8ba1Web\u63a5\u53e3\u65f6\uff0c\u4f7f\u7528HTTPS\uff08HTTP over SSL\/TLS\uff09\u6765\u52a0\u5bc6\u901a\u4fe1\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002HTTPS\u53ef\u4ee5\u9632\u6b62\u4e2d\u95f4\u4eba\u653b\u51fb\u548c\u6570\u636e\u6cc4\u9732\uff0c\u786e\u4fdd\u6570\u636e\u5728\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e4b\u95f4\u7684\u5b89\u5168\u4f20\u8f93\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528Python Flask\u6846\u67b6\u5b9e\u73b0HTTPS\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>from flask import Flask\nfrom flask_sslify import SSLify\n\napp = Flask(__name__)\nsslify = SSLify(app)\n\n@app.route('\/')\ndef index():\n    return 'Hello, World!'\n\nif __name__ == '__main__':\n    app.run()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u5b9e\u65bd\u8bbf\u95ee\u9650\u5236<br \/>\u4e3a\u4e86\u907f\u514d\u6076\u610f\u7528\u6237\u7684\u653b\u51fb\uff0c\u5fc5\u987b\u5bf9Web\u63a5\u53e3\u8fdb\u884c\u8bbf\u95ee\u9650\u5236\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Nginx\u914d\u7f6eIP\u8bbf\u95ee\u63a7\u5236\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>location \/api\/ {\n    allow 192.168.0.0\/24;\n    deny all;\n    proxy_pass http:\/\/localhost:8000;\n}<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u53ea\u6709IP\u5730\u5740\u8303\u56f4\u5728192.168.0.0\/24\u5185\u7684\u5ba2\u6237\u7aef\u624d\u80fd\u8bbf\u95ee\/api\/\u8def\u5f84\u4e0b\u7684\u63a5\u53e3\u3002<\/p>\n<ol>\n<li>\u5f3a\u5316\u8eab\u4efd\u8ba4\u8bc1<br \/>\u4e3a\u4e86\u786e\u4fdd\u53ea\u6709\u6388\u6743\u7528\u6237\u53ef\u4ee5\u8bbf\u95eeWeb\u63a5\u53e3\uff0c\u5f3a\u5316\u8eab\u4efd\u8ba4\u8bc1\u662f\u5fc5\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Flask-HTTPAuth\u6a21\u5757\u5b9e\u73b0\u57fa\u672c\u8eab\u4efd\u8ba4\u8bc1\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>from flask import Flask\nfrom flask_httpauth import HTTPBasicAuth\n\napp = Flask(__name__)\nauth = HTTPBasicAuth()\n\nusers = {\n    'admin': 'password'\n}\n\n@auth.verify_password\ndef verify_password(username, password):\n    if username in users and password == users[username]:\n        return True\n    else:\n        return False\n\n@app.route('\/')\n@auth.login_required\ndef index():\n    return 'Hello, authenticated user!'\n\nif __name__ == '__main__':\n    app.run()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u53ea\u6709\u63d0\u4f9b\u6b63\u786e\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u624d\u80fd\u8bbf\u95ee\u9996\u9875\u3002<\/p>\n<ol>\n<li>\u8f93\u5165\u9a8c\u8bc1\u4e0e\u8fc7\u6ee4<br \/>\u7528\u6237\u8f93\u5165\u662fWeb\u5e94\u7528\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u5b89\u5168\u98ce\u9669\u6765\u6e90\u3002\u4e3a\u4e86\u9632\u6b62SQL\u6ce8\u5165\u548c\u8de8\u7ad9\u811a\u672c\u7b49\u653b\u51fb\uff0c\u5fc5\u987b\u5bf9\u7528\u6237\u8f93\u5165\u8fdb\u884c\u9a8c\u8bc1\u4e0e\u8fc7\u6ee4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Python Flask\u6846\u67b6\u5b9e\u73b0\u8f93\u5165\u9a8c\u8bc1\u4e0e\u8fc7\u6ee4\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>from flask import Flask, request\nimport re\n\napp = Flask(__name__)\n\n@app.route('\/search')\ndef search():\n    keyword = request.args.get('keyword')\n    if not re.match(r'^[a-zA-Z0-9s]+$', keyword):\n        return 'Invalid keyword.'\n    else:\n        # \u6267\u884c\u641c\u7d22\u903b\u8f91\n        pass\n\nif __name__ == '__main__':\n    app.run()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u5bf9\u7528\u6237\u8f93\u5165\u7684\u5173\u952e\u5b57\u8fdb\u884c\u9a8c\u8bc1\uff0c\u786e\u4fdd\u53ea\u6709\u5b57\u6bcd\u3001\u6570\u5b57\u548c\u7a7a\u683c\u7ec4\u6210\u3002<\/p>\n<p>\u7ed3\u8bba\uff1a<br \/>\u5b9e\u65bd\u5f3a\u5927\u7684Web\u63a5\u53e3\u5b89\u5168\u6027\u7b56\u7565\u5bf9\u4e8e\u4fdd\u62a4Web\u5e94\u7528\u7684\u673a\u5bc6\u6027\u3001\u5b8c\u6574\u6027\u548c\u53ef\u7528\u6027\u81f3\u5173\u91cd\u8981\u3002\u672c\u6587\u4ecb\u7ecd\u4e86\u4e00\u4e9b\u6709\u6548\u7684\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4e86\u76f8\u5173\u7684\u4ee3\u7801\u793a\u4f8b\u3002\u7136\u800c\uff0c\u4e3a\u4e86\u8fdb\u4e00\u6b65\u63d0\u5347Web\u63a5\u53e3\u7684\u5b89\u5168\u6027\uff0c\u4ecd\u9700\u4e0d\u65ad\u5b66\u4e60\u548c\u4e86\u89e3\u6700\u65b0\u7684\u5b89\u5168\u6280\u672f\u548c\u653b\u51fb\u624b\u6cd5\uff0c\u5e76\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8c03\u6574\u548c\u4f18\u5316\u5b89\u5168\u7b56\u7565\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u5b9e\u65bd\u5f3a\u5927\u7684Web\u63a5\u53e3\u5b89\u5168\u6027\u7b56\u7565\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728Linux\u670d\u52a1\u5668\u4e0a\u5b9e\u65bd\u5f3a\u5927\u7684Web\u63a5\u53e3\u5b89\u5168\u6027\u7b56\u7565\uff1f \u6982\u8ff0\uff1a\u968f\u7740\u4e92\u8054\u7f51\u7684\u5feb\u901f\u53d1\u5c55\uff0cWeb\u5e94\u7528\u6210\u4e3a\u4e86\u4f17\u591a\u4f01\u4e1a\u548c\u4e2a\u4eba\u8fdb\u884c\u4e1a\u52a1\u4ea4\u4e92\u7684\u9996\u9009\u65b9\u5f0f\u3002\u7136\u800c\uff0c\u968f\u4e4b\u800c\u6765\u7684\u662fWeb\u63a5\u53e3\u5b89\u5168\u6027\u7684\u5a01\u80c1\u4e5f\u6025\u5267\u589e\u52a0\u3002\u4e3a\u4e86\u4fdd\u62a4Web\u5e94\u7528\u7684\u5b89\u5168\u6027\uff0cLinux\u670d\u52a1\u5668\u4e0a\u7684Web\u63a5\u53e3\u9700\u8981\u5b9e\u65bd\u5f3a\u5927\u7684\u5b89\u5168\u6027\u7b56\u7565\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u4e00\u4e9b\u6709\u6548\u7684\u65b9\u6cd5\u6765\u63d0\u5347Web\u63a5\u53e3\u7684\u5b89\u5168\u6027\uff0c\u5e76\u9644\u4e0a\u76f8\u5e94\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u4f7f\u7528HTTPS\u52a0\u5bc6\u901a\u4fe1\u5728\u8bbe\u8ba1Web\u63a5\u53e3\u65f6\uff0c\u4f7f\u7528HTTPS\uff08HTTP over SSL\/TLS\uff09\u6765\u52a0\u5bc6\u901a\u4fe1\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002HTTPS\u53ef\u4ee5\u9632\u6b62\u4e2d\u95f4\u4eba\u653b\u51fb\u548c\u6570\u636e\u6cc4\u9732\uff0c\u786e\u4fdd\u6570\u636e\u5728\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4e4b\u95f4\u7684\u5b89\u5168\u4f20\u8f93\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528Python Flask\u6846\u67b6\u5b9e\u73b0HTTPS\u7684\u793a\u4f8b\u4ee3\u7801\uff1a from flask import Flask from flask_sslify import SSLify app = Flask(__name__) sslify = SSLify(app) @app.route(&#8216;\/&#8217;) def index(): return &#8216;Hello, World!&#8217; if __name__ == &#8216;__main__&#8217;: app.run() \u767b\u5f55\u540e\u590d\u5236 \u5b9e\u65bd\u8bbf\u95ee\u9650\u5236\u4e3a\u4e86\u907f\u514d\u6076\u610f\u7528\u6237\u7684\u653b\u51fb\uff0c\u5fc5\u987b\u5bf9Web\u63a5\u53e3\u8fdb\u884c\u8bbf\u95ee\u9650\u5236\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Nginx\u914d\u7f6eIP\u8bbf\u95ee\u63a7\u5236\u7684\u793a\u4f8b\u4ee3\u7801\uff1a location \/api\/ { allow 192.168.0.0\/24; deny all; proxy_pass http:\/\/localhost:8000; } \u767b\u5f55\u540e\u590d\u5236 \u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u53ea\u6709IP\u5730\u5740\u8303\u56f4\u5728192.168.0.0\/24\u5185\u7684\u5ba2\u6237\u7aef\u624d\u80fd\u8bbf\u95ee\/api\/\u8def\u5f84\u4e0b\u7684\u63a5\u53e3\u3002 \u5f3a\u5316\u8eab\u4efd\u8ba4\u8bc1\u4e3a\u4e86\u786e\u4fdd\u53ea\u6709\u6388\u6743\u7528\u6237\u53ef\u4ee5\u8bbf\u95eeWeb\u63a5\u53e3\uff0c\u5f3a\u5316\u8eab\u4efd\u8ba4\u8bc1\u662f\u5fc5\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Flask-HTTPAuth\u6a21\u5757\u5b9e\u73b0\u57fa\u672c\u8eab\u4efd\u8ba4\u8bc1\u7684\u793a\u4f8b\u4ee3\u7801\uff1a from flask import Flask from flask_httpauth import HTTPBasicAuth app [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-62421","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=62421"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/62421\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=62421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=62421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=62421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}