{"id":63874,"date":"2025-04-29T09:21:56","date_gmt":"2025-04-29T01:21:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63874\/"},"modified":"2025-04-29T09:21:56","modified_gmt":"2025-04-29T01:21:56","slug":"nginx%e6%80%8e%e4%b9%88%e7%94%a8-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63874\/","title":{"rendered":"nginx\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  nginx \u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u5f00\u6e90 web \u670d\u52a1\u5668\uff0c\u4ee5\u4e0b\u662f\u4f7f\u7528\u5b83\u7684\u6b65\u9aa4\uff1a\u5b89\u88c5 nginx\uff1a\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u5b89\u88c5\uff0c\u5982 linux\u3001macos \u6216 windows\u3002\u914d\u7f6e nginx\uff1a\u7f16\u8f91\u4e3b\u914d\u7f6e\u6587\u4ef6\uff0c\u5b9a\u4e49\u4fa6\u542c\u5730\u5740\u3001\u8bbe\u7f6e\u6839\u76ee\u5f55\u548c\u7d22\u5f15\u6587\u4ef6\u3002\u542f\u52a8 nginx\uff1a\u4f7f\u7528\u7cfb\u7edf\u547d\u4ee4\u542f\u52a8\u670d\u52a1\u3002\u6d4b\u8bd5 nginx\uff1a\u53d1\u9001 http \u8bf7\u6c42\u4ee5\u9a8c\u8bc1\u5176\u6b63\u5e38\u5de5\u4f5c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202407\/11\/2024071112395690276.jpg\" class=\"aligncenter\" title=\"nginx\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"nginx\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Nginx<\/strong><\/p>\n<p>Nginx\uff08engine x\uff09\u662f\u4e00\u79cd\u5f00\u6e90\u3001\u9ad8\u6027\u80fd\u7684 Web \u670d\u52a1\u5668\uff0c\u4ee5\u5176\u9ad8\u5e76\u53d1\u5904\u7406\u80fd\u529b\u548c\u4f4e\u8d44\u6e90\u6d88\u8017\u800c\u95fb\u540d\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 Nginx \u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5b89\u88c5 Nginx<\/strong><\/p>\n<p>Nginx \u53ef\u7528\u4e8e\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5305\u62ec Linux\u3001macOS \u548c Windows\u3002\u5177\u4f53\u5b89\u88c5\u6b65\u9aa4\u56e0\u5e73\u53f0\u800c\u5f02\u3002<\/p>\n<p><strong>2. \u914d\u7f6e Nginx<\/strong><\/p>\n<p>Nginx \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e \/etc\/\/nginx.conf\uff08Linux\uff09\u6216 \/usr\/local\/etc\/nginx\/nginx.conf\uff08macOS\uff09\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982 nano \u6216 vi\uff09\u6253\u5f00\u8be5\u6587\u4ef6\u3002<\/p>\n<p><strong>3. \u5b9a\u4e49\u4fa6\u542c\u5730\u5740<\/strong><\/p>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u60a8\u9700\u8981\u5b9a\u4e49 Nginx \u4fa6\u542c\u7684 IP \u5730\u5740\u548c\u7aef\u53e3\u3002\u8fd9\u901a\u5e38\u5728 server \u5757\u5185\u5b8c\u6210\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>server {\n    listen 80;\n    server_name example.com;\n\n    # ... \u5176\u4ed6\u914d\u7f6e ...\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u8bbe\u7f6e\u6839\u76ee\u5f55<\/strong><\/p>\n<p>Nginx \u9700\u8981\u77e5\u9053\u6587\u4ef6\u6240\u5728\u7684\u6839\u76ee\u5f55\uff0c\u4ee5\u4fbf\u4e3a\u8bf7\u6c42\u63d0\u4f9b\u670d\u52a1\u3002\u8fd9\u662f\u901a\u8fc7 root \u6307\u4ee4\u6307\u5b9a\u7684\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>root \/var\/www\/example.com;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u8bbe\u7f6e\u7d22\u5f15\u6587\u4ef6<\/strong><\/p>\n<p>\u5f53\u7528\u6237\u8bbf\u95ee\u6ca1\u6709\u660e\u786e\u6307\u5b9a\u6587\u4ef6\u7684\u76ee\u5f55\u65f6\uff0cNginx \u4f1a\u641c\u7d22\u7d22\u5f15\u6587\u4ef6\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cNginx \u5bfb\u627e index.html \u548c index.php\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7 index \u6307\u4ee4\u6dfb\u52a0\u6216\u66f4\u6539\u7d22\u5f15\u6587\u4ef6\u5217\u8868\u3002<\/p>\n<p><strong>6. \u542f\u52a8 Nginx<\/strong><\/p>\n<p>\u4e00\u65e6\u60a8\u7684\u914d\u7f6e\u6587\u4ef6\u914d\u7f6e\u597d\uff0c\u60a8\u5c31\u53ef\u4ee5\u542f\u52a8 Nginx \u670d\u52a1\u3002\u8fd9\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u7cfb\u7edf\u547d\u4ee4\u5b8c\u6210\uff0c\u5982\uff1a<\/p>\n<pre>service nginx start<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>7. \u6d4b\u8bd5 Nginx<\/strong><\/p>\n<p>\u8981\u6d4b\u8bd5 Nginx \u662f\u5426\u6b63\u5e38\u5de5\u4f5c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>curl http:\/\/example.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u5411 Nginx \u53d1\u9001\u4e00\u4e2a HTTP \u8bf7\u6c42\u5e76\u6253\u5370\u54cd\u5e94\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528\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>nginx \u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u5f00\u6e90 web \u670d\u52a1\u5668\uff0c\u4ee5\u4e0b\u662f\u4f7f\u7528\u5b83\u7684\u6b65\u9aa4\uff1a\u5b89\u88c5 nginx\uff1a\u6839\u636e\u64cd\u4f5c\u7cfb\u7edf\u5b89\u88c5\uff0c\u5982 linux\u3001macos \u6216 windows\u3002\u914d\u7f6e nginx\uff1a\u7f16\u8f91\u4e3b\u914d\u7f6e\u6587\u4ef6\uff0c\u5b9a\u4e49\u4fa6\u542c\u5730\u5740\u3001\u8bbe\u7f6e\u6839\u76ee\u5f55\u548c\u7d22\u5f15\u6587\u4ef6\u3002\u542f\u52a8 nginx\uff1a\u4f7f\u7528\u7cfb\u7edf\u547d\u4ee4\u542f\u52a8\u670d\u52a1\u3002\u6d4b\u8bd5 nginx\uff1a\u53d1\u9001 http \u8bf7\u6c42\u4ee5\u9a8c\u8bc1\u5176\u6b63\u5e38\u5de5\u4f5c\u3002 \u5982\u4f55\u4f7f\u7528 Nginx Nginx\uff08engine x\uff09\u662f\u4e00\u79cd\u5f00\u6e90\u3001\u9ad8\u6027\u80fd\u7684 Web \u670d\u52a1\u5668\uff0c\u4ee5\u5176\u9ad8\u5e76\u53d1\u5904\u7406\u80fd\u529b\u548c\u4f4e\u8d44\u6e90\u6d88\u8017\u800c\u95fb\u540d\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 Nginx \u7684\u6b65\u9aa4\uff1a 1. \u5b89\u88c5 Nginx Nginx \u53ef\u7528\u4e8e\u591a\u79cd\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5305\u62ec Linux\u3001macOS \u548c Windows\u3002\u5177\u4f53\u5b89\u88c5\u6b65\u9aa4\u56e0\u5e73\u53f0\u800c\u5f02\u3002 2. \u914d\u7f6e Nginx Nginx \u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8e \/etc\/\/nginx.conf\uff08Linux\uff09\u6216 \/usr\/local\/etc\/nginx\/nginx.conf\uff08macOS\uff09\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982 nano \u6216 vi\uff09\u6253\u5f00\u8be5\u6587\u4ef6\u3002 3. \u5b9a\u4e49\u4fa6\u542c\u5730\u5740 \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u60a8\u9700\u8981\u5b9a\u4e49 Nginx \u4fa6\u542c\u7684 IP \u5730\u5740\u548c\u7aef\u53e3\u3002\u8fd9\u901a\u5e38\u5728 server \u5757\u5185\u5b8c\u6210\uff0c\u5982\u4e0b\u6240\u793a\uff1a server { listen 80; server_name example.com; # [&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-63874","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63874","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=63874"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63874\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63874"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63874"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}