{"id":146,"date":"2023-08-24T08:14:39","date_gmt":"2023-08-24T00:14:39","guid":{"rendered":"http:\/\/8.130.131.184\/wordpress\/?p=146"},"modified":"2023-08-24T08:21:59","modified_gmt":"2023-08-24T00:21:59","slug":"nginx%e9%85%8d%e7%bd%ae%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/xianyijitan.top\/?p=146","title":{"rendered":"Nginx\u914d\u7f6e\u89e3\u6790"},"content":{"rendered":"<h4>Nginx\u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e3a\/usr\/local\/nginx\/conf\/nginx.conf\uff0c\u914d\u7f6e\u8bed\u53e5\u7684\u683c\u5f0f\u4e3a\u201c\u5173\u952e\u5b57 \u503c;\u201d\uff08\u672b\u5c3e\u4ee5\u5206\u53f7\u8868\u793a\u7ed3\u675f\uff09\uff0c\u4ee5\u201c#\u201d\u5f00\u59cb\u7684\u90e8\u5206\u8868\u793a\u6ce8\u91ca\u3002\u914d\u7f6e\u7ed3\u6784\u5982\u4e0b\uff1a<\/h4>\n<pre><code class=\"language-shell\">http{\n    ... \u2026\n    server {\n        \u2026 \u2026\n        location \/ {\n            \u2026 \u2026\n        }\n    }\n}<\/code><\/pre>\n<h4>\u5176\u4e2d\uff0cHTTP\u914d\u7f6e\u4f7f\u7528\u201chttp { }\u201d\u754c\u5b9a\u6807\u8bb0\uff0c\u865a\u62dfWeb\u4e3b\u673a\u3001PHP\u89e3\u6790\u7b49\u4e00\u7cfb\u5217\u8bbe\u7f6e\uff0c\u5176\u4e2d\u5927\u90e8\u5206\u914d\u7f6e\u8bed\u53e5\u90fd\u5305\u542b\u5728\u5b50\u754c\u5b9a\u6807\u8bb0\u201cserver { }\u201d\u5185\u3002<\/h4>\n<pre><code class=\"language-shell\">http  {\n\u2026\u2026\nserver {                      \/\/\u5b9a\u4e49\u865a\u62df\u4e3b\u673a\n        listen       80;\n        server_name   localhost;\n        location  \/  {                              \/\/\u53d1\u5e03\u76ee\u5f55\n            root   html;\n            index   index.html index.htm;\n        }\n     }\n}<\/code><\/pre>\n<h4>\u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0clisten\u8bed\u53e5\u5141\u8bb8\u540c\u65f6\u9650\u5b9aIP\u5730\u5740\uff0c\u91c7\u7528\u201cIP\u5730\u5740:\u7aef\u53e3\u201d\u5f62\u5f0f\uff1broot\u8bed\u53e5\u7528\u6765\u8bbe\u7f6e\u7279\u5b9a\u8bbf\u95ee\u4f4d\u7f6e\uff08\u5982\u201clocation \/\u201d\u8868\u793a\u6839\u76ee\u5f55\uff09\u7684\u7f51\u9875\u6587\u6863\u8def\u5f84\uff0c\u9ed8\u8ba4\u4e3aNginx\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684html\/\u5b50\u76ee\u5f55\uff0c\u6839\u636e\u9700\u8981\u53ef\u6539\u4e3a\/var\/www\/html\u7b49\u5176\u4ed6\u8def\u5f84\u3002<\/h4>\n<h4><strong>\u7528\u6237\u8ba4\u8bc1<\/strong><\/h4>\n<h5>1\u3001\u914d\u7f6eNginx\u7528\u6237\u8ba4\u8bc1<\/h5>\n<h5>\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\/usr\/local\/nginx\/conf\/nginx.conf\uff1a<\/h5>\n<pre><code class=\"language-shell\">[root@proxy nginx]# vim \/usr\/local\/nginx\/conf\/nginx.conf\n.. ..\nserver {\n        listen       80;\n        server_name  localhost;\n        auth_basic &quot;Input Password:&quot;;                    \/\/\u8ba4\u8bc1\u63d0\u793a\u7b26\u4fe1\u606f\n        auth_basic_user_file  &quot;\/usr\/local\/nginx\/pass&quot;;   \/\/\u8ba4\u8bc1\u7684\u5bc6\u7801\u6587\u4ef6\n        location \/ {\n            root   html;\n            index  index.html index.htm;\n        }\n  }<\/code><\/pre>\n<h5>2\u3001\u5b89\u88c5httpd-tools\uff0c\u751f\u6210\u5bc6\u7801\u6587\u4ef6\uff0c\u4f7f\u7528htpasswd\u547d\u4ee4\u521b\u5efa\u8d26\u6237\u6587\u4ef6\uff1a<\/h5>\n<pre><code class=\"language-shell\">[root@proxy nginx]# yum -y install  httpd-tools\n[root@proxy nginx]# htpasswd -c \/usr\/local\/nginx\/pass   lisi        \/\/\u521b\u5efa\u5bc6\u7801\u6587\u4ef6\nNew password:                                                       \/\/\u5bc6\u7801\uff1a123456\nRe-type new password: \nAdding password for user lisi\n[root@proxy nginx]# \/usr\/local\/nginx\/sbin\/nginx -s reload         \/\/\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6 <\/code><\/pre>\n<p>\u67e5\u770b\u8be5\u7f51\u7ad9\u76ee\u524d\u9700\u8981\u4f7f\u7528\u8d26\u53f7\u4e0e\u5bc6\u7801\u767b\u5f55<\/p>\n<h5>\u53ef\u4ee5\u4f7f\u7528 htpasswd \u547d\u4ee4\u8ffd\u52a0\u8ba4\u8bc1\u8d26\u6237:<\/h5>\n<pre><code class=\"language-shell\">[root@proxy ~]# htpasswd  \/usr\/local\/nginx\/pass   zhangsan     \/\/\u8ffd\u52a0\u7528\u6237\uff0c\u4e0d\u4f7f\u7528-c\u9009\u9879\nNew password: \nRe-type new password: \nAdding password for user zhangsan\n[root@proxy nginx]# \/usr\/local\/nginx\/sbin\/nginx -s reload         \/\/\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6 <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Nginx\u7684\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e3a\/usr\/local\/nginx\/conf\/nginx.conf\uff0c\u914d\u7f6e\u8bed\u53e5\u7684\u683c\u5f0f\u4e3a\u201c\u5173\u952e\u5b57 \u503c;\u201d\uff08\u672b\u5c3e\u4ee5\u5206\u53f7\u8868\u793a\u7ed3\u675f\uff09\uff0c\u4ee5\u201c#\u201d\u5f00\u59cb\u7684\u90e8\u5206\u8868\u793a\u6ce8\u91ca\u3002\u914d\u7f6e\u7ed3\u6784\u5982\u4e0b\uff1a http{ &#8230; \u2026 server { \u2026 \u2026 location \/ { \u2026 \u2026 } } } \u5176\u4e2d\uff0cHTTP\u914d\u7f6e\u4f7f\u7528\u201chttp { }\u201d\u754c\u5b9a\u6807\u8bb0\uff0c\u865a\u62dfWeb\u4e3b\u673a\u3001PHP\u89e3\u6790\u7b49\u4e00\u7cfb\u5217\u8bbe\u7f6e\uff0c\u5176\u4e2d\u5927\u90e8\u5206\u914d\u7f6e\u8bed\u53e5\u90fd\u5305\u542b\u5728\u5b50\u754c\u5b9a\u6807\u8bb0\u201cserver { }\u201d\u5185\u3002 http { \u2026\u2026 server { \/\/\u5b9a\u4e49\u865a\u62df\u4e3b\u673a listen 80; server_name localhost; location \/ { \/\/\u53d1\u5e03\u76ee\u5f55 root html; index index.html index.htm; } } } \u4e0a\u8ff0\u914d\u7f6e\u4e2d\uff0clisten\u8bed\u53e5\u5141\u8bb8\u540c\u65f6\u9650\u5b9aIP\u5730\u5740\uff0c\u91c7\u7528\u201cIP\u5730\u5740:\u7aef\u53e3\u201d\u5f62\u5f0f\uff1broot\u8bed\u53e5\u7528\u6765\u8bbe\u7f6e\u7279\u5b9a\u8bbf\u95ee\u4f4d\u7f6e\uff08\u5982\u201clocation \/\u201d\u8868\u793a\u6839\u76ee\u5f55\uff09\u7684\u7f51\u9875\u6587\u6863\u8def\u5f84\uff0c\u9ed8\u8ba4\u4e3aNginx\u5b89\u88c5\u76ee\u5f55\u4e0b\u7684html\/\u5b50\u76ee\u5f55\uff0c\u6839\u636e\u9700\u8981\u53ef\u6539\u4e3a\/var\/www\/html\u7b49\u5176\u4ed6\u8def\u5f84\u3002 \u7528\u6237\u8ba4\u8bc1 1\u3001\u914d\u7f6eNginx\u7528\u6237\u8ba4\u8bc1 \u4fee\u6539\u914d\u7f6e\u6587\u4ef6\/usr\/local\/nginx\/conf\/nginx.conf\uff1a [root@proxy nginx]# vim \/usr\/local\/nginx\/conf\/nginx.conf .. .. server { listen 80; server_name localhost; auth_basic &quot;Input Password:&quot;; \/\/\u8ba4\u8bc1\u63d0\u793a\u7b26\u4fe1\u606f auth_basic_user_file &quot;\/usr\/local\/nginx\/pass&quot;; \/\/\u8ba4\u8bc1\u7684\u5bc6\u7801\u6587\u4ef6 location \/ { root html; index index.html index.htm; } } 2\u3001\u5b89\u88c5httpd-tools\uff0c\u751f\u6210\u5bc6\u7801\u6587\u4ef6\uff0c\u4f7f\u7528htpasswd\u547d\u4ee4\u521b\u5efa\u8d26\u6237\u6587\u4ef6\uff1a [root@proxy nginx]# yum -y install httpd-tools [root@proxy nginx]# htpasswd -c \/usr\/local\/nginx\/pass lisi \/\/\u521b\u5efa\u5bc6\u7801\u6587\u4ef6 New password: \/\/\u5bc6\u7801\uff1a123456 Re-type new password: Adding password for user lisi [root@proxy nginx]# \/usr\/local\/nginx\/sbin\/nginx -s reload \/\/\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6 \u67e5\u770b\u8be5\u7f51\u7ad9\u76ee\u524d\u9700\u8981\u4f7f\u7528\u8d26\u53f7\u4e0e\u5bc6\u7801\u767b\u5f55 \u53ef\u4ee5\u4f7f\u7528 htpasswd \u547d\u4ee4\u8ffd\u52a0\u8ba4\u8bc1\u8d26\u6237: [root@proxy ~]# htpasswd \/usr\/local\/nginx\/pass zhangsan \/\/\u8ffd\u52a0\u7528\u6237\uff0c\u4e0d\u4f7f\u7528-c\u9009\u9879 New password: Re-type new password: Adding password for user zhangsan [root@proxy nginx]# \/usr\/local\/nginx\/sbin\/nginx -s reload \/\/\u91cd\u65b0\u52a0\u8f7d\u914d\u7f6e\u6587\u4ef6<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-146","post","type-post","status-publish","format-standard","hentry","category-lixx"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=146"}],"version-history":[{"count":2,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=\/wp\/v2\/posts\/146\/revisions\/148"}],"wp:attachment":[{"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xianyijitan.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}