{"id":63840,"date":"2025-04-29T14:15:49","date_gmt":"2025-04-29T06:15:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63840\/"},"modified":"2025-04-29T14:15:49","modified_gmt":"2025-04-29T06:15:49","slug":"nginx%e5%90%8c%e4%b8%80%e4%b8%aa%e7%ab%af%e5%8f%a3%e4%b8%8d%e5%90%8c%e5%9f%9f%e5%90%8d%e5%a6%82%e4%bd%95%e9%85%8d%e7%bd%ae-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63840\/","title":{"rendered":"nginx\u540c\u4e00\u4e2a\u7aef\u53e3\u4e0d\u540c\u57df\u540d\u5982\u4f55\u914d\u7f6e"},"content":{"rendered":"<blockquote><p>\n  \u5728 nginx \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e3a\u4e0d\u540c\u57df\u540d\u521b\u5efa\u865a\u62df\u4e3b\u673a\u6765\u5b9e\u73b0\u540c\u4e00\u7aef\u53e3\u914d\u7f6e\u591a\u4e2a\u7f51\u7ad9\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\u3002\u6307\u5b9a\u670d\u52a1\u5668\u5757\uff0c\u5e76\u6307\u5b9a\u7aef\u53e3\u3001\u57df\u540d\u548c\u6839\u76ee\u5f55\u3002\u6d4b\u8bd5\u914d\u7f6e\u3002\u9a8c\u8bc1\u914d\u7f6e\u3002\u5176\u4ed6\u914d\u7f6e\u9009\u9879\uff1alocation\u3001rewrite \u548c proxy_pass \u6307\u4ee4\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/06\/2024060615181834227.jpg\" class=\"aligncenter\" title=\"nginx\u540c\u4e00\u4e2a\u7aef\u53e3\u4e0d\u540c\u57df\u540d\u5982\u4f55\u914d\u7f6e\u63d2\u56fe\" alt=\"nginx\u540c\u4e00\u4e2a\u7aef\u53e3\u4e0d\u540c\u57df\u540d\u5982\u4f55\u914d\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>Nginx \u4e3a\u4e0d\u540c\u57df\u540d\u914d\u7f6e\u540c\u4e00\u7aef\u53e3<\/strong><\/p>\n<p>\u5728 Nginx \u4e2d\uff0c\u53ef\u4ee5\u4e3a\u7ed1\u5b9a\u5230\u540c\u4e00\u7aef\u53e3\u7684\u4e0d\u540c\u57df\u540d\u914d\u7f6e\u865a\u62df\u4e3b\u673a\uff0c\u4ece\u800c\u5141\u8bb8\u540c\u4e00 IP \u5730\u5740\u6258\u7ba1\u591a\u4e2a\u7f51\u7ad9\u3002\u8981\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u5728 Nginx \u914d\u7f6e\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a\/etc\/\/conf.d\/example.com.conf\u3002<\/p>\n<p><strong>2. \u6307\u5b9a\u670d\u52a1\u5668\u5757<\/strong><\/p>\n<p>\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u4e00\u4e2a\u65b0\u7684\u670d\u52a1\u5668\u5757\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>server {\n    listen 80;  # \u6307\u5b9a\u7aef\u53e3\u4e3a 80\n    server_name example.com www.example.com;  # \u6307\u5b9a\u57df\u540d\n    root \/var\/www\/example.com;  # \u6307\u5b9a\u7f51\u7ad9\u6839\u76ee\u5f55\n    index index.php index.html;  # \u6307\u5b9a\u9ed8\u8ba4\u7d22\u5f15\u6587\u4ef6\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5bf9\u4e8e\u5176\u4ed6\u57df\u540d\uff0c\u8bf7\u521b\u5efa\u7c7b\u4f3c\u7684\u670d\u52a1\u5668\u5757\uff0c\u4f46\u66f4\u65b0 server_name \u548c root \u8bbe\u7f6e\u3002<\/p>\n<p><strong>3. \u6d4b\u8bd5\u914d\u7f6e<\/strong><\/p>\n<p>\u4fdd\u5b58\u914d\u7f6e\u6587\u4ef6\u5e76\u91cd\u65b0\u542f\u52a8 Nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff1a<\/p>\n<pre>sudo systemctl restart nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u9a8c\u8bc1\u914d\u7f6e<\/strong><\/p>\n<p>\u4f7f\u7528 cURL \u5de5\u5177\u6d4b\u8bd5\u914d\u7f6e\uff1a<\/p>\n<pre>curl -I http:\/\/example.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5e94\u8be5\u8fd4\u56de\u7f51\u7ad9\u7684 HTTP \u5934\u4fe1\u606f\u3002<\/p>\n<p><strong>5. \u5176\u4ed6\u914d\u7f6e\u9009\u9879<\/strong><\/p>\n<ul>\n<li> <strong>location \u6307\u4ee4\uff1a<\/strong>\u53ef\u4ee5\u7528\u4e8e\u6307\u5b9a\u7279\u5b9a URI \u8def\u5f84\u7684\u914d\u7f6e\uff0c\u4f8b\u5982\u4e3a\u67d0\u4e9b\u76ee\u5f55\u542f\u7528 SSL\u3002<\/li>\n<li> <strong>rewrite \u6307\u4ee4\uff1a<\/strong>\u53ef\u4ee5\u7528\u4e8e\u91cd\u5199 URL\uff0c\u4f8b\u5982\u5c06 www \u524d\u7f00\u4ece\u57df\u540d\u4e2d\u5220\u9664\u3002<\/li>\n<li> <strong>proxy_pass \u6307\u4ee4\uff1a<\/strong>\u53ef\u4ee5\u7528\u4e8e\u5c06\u8bf7\u6c42\u4ee3\u7406\u5230\u4e0d\u540c\u7684\u670d\u52a1\u5668\u6216\u7aef\u53e3\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u914d\u7f6e\u9009\u9879\uff0c\u53ef\u4ee5\u5728 Nginx \u4e0a\u4e3a\u4e0d\u540c\u57df\u540d\u914d\u7f6e\u4e00\u4e2a\u7aef\u53e3\uff0c\u4ece\u800c\u5141\u8bb8\u5728\u4e00\u4e2a\u670d\u52a1\u5668\u4e0a\u6258\u7ba1\u591a\u4e2a\u7f51\u7ad9\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u540c\u4e00\u4e2a\u7aef\u53e3\u4e0d\u540c\u57df\u540d\u5982\u4f55\u914d\u7f6e\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>\u5728 nginx \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e3a\u4e0d\u540c\u57df\u540d\u521b\u5efa\u865a\u62df\u4e3b\u673a\u6765\u5b9e\u73b0\u540c\u4e00\u7aef\u53e3\u914d\u7f6e\u591a\u4e2a\u7f51\u7ad9\u3002\u6b65\u9aa4\u5982\u4e0b\uff1a\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\u3002\u6307\u5b9a\u670d\u52a1\u5668\u5757\uff0c\u5e76\u6307\u5b9a\u7aef\u53e3\u3001\u57df\u540d\u548c\u6839\u76ee\u5f55\u3002\u6d4b\u8bd5\u914d\u7f6e\u3002\u9a8c\u8bc1\u914d\u7f6e\u3002\u5176\u4ed6\u914d\u7f6e\u9009\u9879\uff1alocation\u3001rewrite \u548c proxy_pass \u6307\u4ee4\u3002 Nginx \u4e3a\u4e0d\u540c\u57df\u540d\u914d\u7f6e\u540c\u4e00\u7aef\u53e3 \u5728 Nginx \u4e2d\uff0c\u53ef\u4ee5\u4e3a\u7ed1\u5b9a\u5230\u540c\u4e00\u7aef\u53e3\u7684\u4e0d\u540c\u57df\u540d\u914d\u7f6e\u865a\u62df\u4e3b\u673a\uff0c\u4ece\u800c\u5141\u8bb8\u540c\u4e00 IP \u5730\u5740\u6258\u7ba1\u591a\u4e2a\u7f51\u7ad9\u3002\u8981\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a 1. \u521b\u5efa\u914d\u7f6e\u6587\u4ef6 \u5728 Nginx \u914d\u7f6e\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a\/etc\/\/conf.d\/example.com.conf\u3002 2. \u6307\u5b9a\u670d\u52a1\u5668\u5757 \u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6307\u5b9a\u4e00\u4e2a\u65b0\u7684\u670d\u52a1\u5668\u5757\uff0c\u5982\u4e0b\u6240\u793a\uff1a server { listen 80; # \u6307\u5b9a\u7aef\u53e3\u4e3a 80 server_name example.com www.example.com; # \u6307\u5b9a\u57df\u540d root \/var\/www\/example.com; # \u6307\u5b9a\u7f51\u7ad9\u6839\u76ee\u5f55 index index.php index.html; # \u6307\u5b9a\u9ed8\u8ba4\u7d22\u5f15\u6587\u4ef6 } \u767b\u5f55\u540e\u590d\u5236 \u5bf9\u4e8e\u5176\u4ed6\u57df\u540d\uff0c\u8bf7\u521b\u5efa\u7c7b\u4f3c\u7684\u670d\u52a1\u5668\u5757\uff0c\u4f46\u66f4\u65b0 server_name \u548c root \u8bbe\u7f6e\u3002 3. \u6d4b\u8bd5\u914d\u7f6e \u4fdd\u5b58\u914d\u7f6e\u6587\u4ef6\u5e76\u91cd\u65b0\u542f\u52a8 Nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff1a sudo [&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-63840","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63840","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=63840"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63840\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}