{"id":51109,"date":"2024-10-08T16:09:57","date_gmt":"2024-10-08T08:09:57","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51109\/"},"modified":"2024-10-08T16:09:57","modified_gmt":"2024-10-08T08:09:57","slug":"nginx-%e6%95%99%e7%a8%8b%ef%bc%9a%e9%97%9c%e6%96%bc-nginx","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51109\/","title":{"rendered":"Nginx \u6559\u7a0b\uff1a\u95dc\u65bc Nginx"},"content":{"rendered":"<h1 id=\"nginx-%e6%95%99%e7%a8%8b%ef%bc%9a%e9%97%9c%e6%96%bc-nginx-ZPyjHcRVpR\">Nginx \u6559\u7a0b\uff1a\u95dc\u65bc Nginx<\/h1>\n<p>Nginx\uff08\u767c\u97f3\u70ba\u201cengine-x\u201d\uff09\u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u6700\u521d\u7531\u4fc4\u7f85\u65af\u7684\u7a0b\u5f0f\u8a2d\u8a08\u5e2b Igor Sysoev \u958b\u767c\u3002\u81ea2004\u5e74\u9996\u6b21\u767c\u5e03\u4ee5\u4f86\uff0cNginx \u8fc5\u901f\u6210\u70ba\u5168\u7403\u6700\u53d7\u6b61\u8fce\u7684\u7db2\u9801\u4f3a\u670d\u5668\u4e4b\u4e00\uff0c\u5c24\u5176\u662f\u5728\u8655\u7406\u9ad8\u6d41\u91cf\u7db2\u7ad9\u6642\uff0c\u5176\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u8868\u73fe\u5c24\u70ba\u7a81\u51fa\u3002<\/p>\n<h2 id=\"nginx-%e7%9a%84%e7%89%b9%e9%bb%9e-ZPyjHcRVpR\">Nginx \u7684\u7279\u9ede<\/h2>\n<ul>\n<li><strong>\u9ad8\u6548\u80fd\uff1a<\/strong> Nginx \u80fd\u5920\u540c\u6642\u8655\u7406\u5927\u91cf\u7684\u9023\u63a5\uff0c\u9019\u4f7f\u5f97\u5b83\u5728\u9ad8\u6d41\u91cf\u7684\u74b0\u5883\u4e2d\u8868\u73fe\u51fa\u8272\u3002\u5176\u975e\u963b\u585e\u7684\u4e8b\u4ef6\u9a45\u52d5\u67b6\u69cb\u4f7f\u5f97 Nginx \u80fd\u5920\u6709\u6548\u5229\u7528\u7cfb\u7d71\u8cc7\u6e90\u3002<\/li>\n<li><strong>\u53cd\u5411\u4ee3\u7406\uff1a<\/strong> Nginx \u53ef\u4ee5\u4f5c\u70ba\u53cd\u5411\u4ee3\u7406\u4f3a\u670d\u5668\uff0c\u5c07\u8acb\u6c42\u8f49\u767c\u5230\u5f8c\u7aef\u4f3a\u670d\u5668\uff0c\u9019\u6a23\u53ef\u4ee5\u63d0\u9ad8\u7db2\u7ad9\u7684\u5b89\u5168\u6027\u548c\u6027\u80fd\u3002<\/li>\n<li><strong>\u8ca0\u8f09\u5747\u8861\uff1a<\/strong> Nginx \u652f\u63f4\u591a\u7a2e\u8ca0\u8f09\u5747\u8861\u7b97\u6cd5\uff0c\u80fd\u5920\u5c07\u6d41\u91cf\u5206\u914d\u5230\u591a\u500b\u4f3a\u670d\u5668\u4e0a\uff0c\u5f9e\u800c\u63d0\u9ad8\u7db2\u7ad9\u7684\u53ef\u7528\u6027\u548c\u7a69\u5b9a\u6027\u3002<\/li>\n<li><strong>\u975c\u614b\u5167\u5bb9\u8655\u7406\uff1a<\/strong> Nginx \u5c0d\u975c\u614b\u5167\u5bb9\uff08\u5982\u5716\u7247\u3001CSS \u548c JavaScript \u6587\u4ef6\uff09\u7684\u8655\u7406\u901f\u5ea6\u975e\u5e38\u5feb\uff0c\u9019\u4f7f\u5f97\u5b83\u6210\u70ba\u975c\u614b\u7db2\u7ad9\u7684\u7406\u60f3\u9078\u64c7\u3002<\/li>\n<\/ul>\n<h2 id=\"nginx-%e7%9a%84%e5%ae%89%e8%a3%9d-ZPyjHcRVpR\">Nginx \u7684\u5b89\u88dd<\/h2>\n<p>\u5728\u5927\u591a\u6578 Linux \u767c\u884c\u7248\u4e2d\uff0c\u5b89\u88dd Nginx \u975e\u5e38\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u57fa\u65bc Ubuntu \u7684\u5b89\u88dd\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install nginx\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Nginx\uff1a<\/p>\n<pre><code>sudo systemctl start nginx\n<\/code><\/pre>\n<p>\u8981\u6aa2\u67e5 Nginx \u662f\u5426\u6b63\u5728\u904b\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>sudo systemctl status nginx\n<\/code><\/pre>\n<h2 id=\"nginx-%e7%9a%84%e5%9f%ba%e6%9c%ac%e9%85%8d%e7%bd%ae-ZPyjHcRVpR\">Nginx \u7684\u57fa\u672c\u914d\u7f6e<\/h2>\n<p>Nginx \u7684\u914d\u7f6e\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc \/etc\/nginx\/nginx.conf\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u914d\u7f6e\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n\n    location \/ {\n        root \/var\/www\/html;\n        index index.html index.htm;\n    }\n\n    error_page 404 \/404.html;\n    location = \/404.html {\n        internal;\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6211\u5011\u8a2d\u7f6e\u4e86\u4e00\u500b\u4f3a\u670d\u5668\uff0c\u76e3\u807d 80 \u7aef\u53e3\uff0c\u4e26\u6307\u5b9a\u4e86\u7db2\u7ad9\u7684\u6839\u76ee\u9304\u548c\u7d22\u5f15\u6587\u4ef6\u3002\u7576\u8acb\u6c42\u7684\u9801\u9762\u4e0d\u5b58\u5728\u6642\uff0c\u5c07\u986f\u793a 404 \u932f\u8aa4\u9801\u9762\u3002<\/p>\n<h2 id=\"%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86%e5%92%8c%e8%b2%a0%e8%bc%89%e5%9d%87%e8%a1%a1-ZPyjHcRVpR\">\u53cd\u5411\u4ee3\u7406\u548c\u8ca0\u8f09\u5747\u8861<\/h2>\n<p>Nginx \u7684\u4e00\u500b\u91cd\u8981\u529f\u80fd\u662f\u4f5c\u70ba\u53cd\u5411\u4ee3\u7406\u4f3a\u670d\u5668\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u53cd\u5411\u4ee3\u7406\u914d\u7f6e\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n\n    location \/ {\n        proxy_pass http:\/\/backend_server;\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u7bc4\u4f8b\u4e2d\uff0c\u6240\u6709\u4f86\u81ea example.com \u7684\u8acb\u6c42\u90fd\u5c07\u88ab\u8f49\u767c\u5230\u540d\u70ba backend_server \u7684\u5f8c\u7aef\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ZPyjHcRVpR\">\u7e3d\u7d50<\/h2>\n<p>Nginx \u662f\u4e00\u6b3e\u529f\u80fd\u5f37\u5927\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u9069\u5408\u7528\u65bc\u5404\u7a2e\u898f\u6a21\u7684\u7db2\u7ad9\u3002\u7121\u8ad6\u662f\u975c\u614b\u5167\u5bb9\u7684\u5feb\u901f\u4ea4\u4ed8\uff0c\u9084\u662f\u4f5c\u70ba\u53cd\u5411\u4ee3\u7406\u548c\u8ca0\u8f09\u5747\u8861\u7684\u89e3\u6c7a\u65b9\u6848\uff0cNginx \u90fd\u80fd\u63d0\u4f9b\u5353\u8d8a\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cNginx \u662f\u4e00\u500b\u503c\u5f97\u8003\u616e\u7684\u9078\u64c7\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u548c <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a> \u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u4e86\u89e3 Nginx \u7684\u529f\u80fd\u8207\u914d\u7f6e\uff0c\u638c\u63e1\u9ad8\u6548\u80fd\u7db2\u9801\u4f3a\u670d\u5668\u7684\u4f7f\u7528\u6280\u5de7\uff0c\u63d0\u5347\u7db2\u7ad9\u6027\u80fd\u8207\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-51109","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51109","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=51109"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51109\/revisions"}],"predecessor-version":[{"id":51110,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51109\/revisions\/51110"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51109"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51109"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51109"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}