{"id":18050,"date":"2024-11-18T13:54:18","date_gmt":"2024-11-18T05:54:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18050\/"},"modified":"2024-11-18T13:54:18","modified_gmt":"2024-11-18T05:54:18","slug":"nginx403%e6%80%8e%e4%b9%88%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18050\/","title":{"rendered":"nginx403\u600e\u4e48\u89e3\u51b3"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u89e3\u51b3 nginx 403 forbidden \u9519\u8bef\uff1f\u68c0\u67e5\u6587\u4ef6\u6216\u76ee\u5f55\u6743\u9650\uff1b2. \u68c0\u67e5 .htaccess \u6587\u4ef6\uff1b3. \u68c0\u67e5 nginx \u914d\u7f6e\u6587\u4ef6\uff1b4. \u91cd\u542f nginx\u3002\u5176\u4ed6\u53ef\u80fd\u539f\u56e0\u8fd8\u5305\u62ec\u9632\u706b\u5899\u89c4\u5219\u3001selinux \u8bbe\u7f6e\u6216\u5e94\u7528\u7a0b\u5e8f\u95ee\u9898\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052720453521570.jpg\" class=\"aligncenter\" title=\"nginx403\u600e\u4e48\u89e3\u51b3\u63d2\u56fe\" alt=\"nginx403\u600e\u4e48\u89e3\u51b3\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u89e3\u51b3 Nginx 403 Forbidden \u9519\u8bef<\/strong><\/p>\n<p><strong>\u5f00\u95e8\u89c1\u5c71\u7684\u56de\u7b54\uff1a<\/strong><\/p>\n<p>Nginx 403 Forbidden \u9519\u8bef\u8868\u793a\u5ba2\u6237\u7aef\u6ca1\u6709\u6743\u9650\u8bbf\u95ee\u8bf7\u6c42\u7684\u8d44\u6e90\u3002\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u5e38\u89c1\u6b65\u9aa4\u5305\u62ec\uff1a<\/p>\n<p><strong>\u8be6\u7ec6\u5c55\u5f00\u56de\u7b54\uff1a<\/strong><\/p>\n<p><strong>1. \u68c0\u67e5\u6587\u4ef6\u6216\u76ee\u5f55\u6743\u9650\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u8bf7\u6c42\u7684\u8d44\u6e90\u5177\u6709\u9002\u5f53\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u6743\u9650\u3002\u901a\u5e38\uff0c\u670d\u52a1\u5668\u5e94\u5177\u6709\u8bfb\u53d6\u548c\u6267\u884c\u6743\u9650\uff0c\u800c\u7528\u6237\u5e94\u4ec5\u5177\u6709\u8bfb\u53d6\u6743\u9650\u3002<\/li>\n<li>\u4f7f\u7528 ls -l \u547d\u4ee4\u68c0\u67e5\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u6743\u9650\uff0c\u5e76\u6839\u636e\u9700\u8981\u4f7f\u7528 chmod \u547d\u4ee4\u8c03\u6574\u5b83\u4eec\u3002<\/li>\n<\/ul>\n<p><strong>2. \u68c0\u67e5 .ht \u6587\u4ef6\uff1a<\/strong><\/p>\n<ul>\n<li>.htaccess \u6587\u4ef6\u53ef\u80fd\u5305\u542b\u9650\u5236\u8bbf\u95ee\u7684\u89c4\u5219\u3002\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u5e76\u786e\u4fdd\u5b83\u4e0d\u5305\u542b\u62d2\u7edd\u8bbf\u95ee\u8bf7\u6c42\u7684\u89c4\u5219\u3002<\/li>\n<\/ul>\n<p><strong>3. \u68c0\u67e5 Nginx \u914d\u7f6e\u6587\u4ef6\uff1a<\/strong><\/p>\n<ul>\n<li>\u6253\u5f00 Nginx \u914d\u7f6e\u6587\u4ef6 (\/etc\/\/nginx.conf \u6216 \/usr\/local\/etc\/nginx\/nginx.conf) \u5e76\u68c0\u67e5\u4ee5\u4e0b\u5757\uff1a<\/li>\n<\/ul>\n<pre>location \/ {\n    # \u5141\u8bb8\u6216\u62d2\u7edd\u8bbf\u95ee\u7684\u89c4\u5219\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u786e\u4fdd\u5141\u8bb8\u8bbf\u95ee\u8bf7\u6c42\u7684\u8d44\u6e90\u3002\u5982\u679c\u627e\u4e0d\u5230\u4efb\u4f55\u663e\u5f0f\u62d2\u7edd\u89c4\u5219\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u6dfb\u52a0 allow all; \u884c\u4ee5\u5141\u8bb8\u6240\u6709\u8bf7\u6c42\u3002<\/li>\n<\/ul>\n<p><strong>4. \u91cd\u542f Nginx\uff1a<\/strong><\/p>\n<ul>\n<li>\u5728\u8fdb\u884c\u4efb\u4f55\u66f4\u6539\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u91cd\u542f Nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff1a<\/li>\n<\/ul>\n<pre>sudo systemctl restart nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u5176\u4ed6\u53ef\u80fd\u7684\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u9632\u706b\u5899\u89c4\u5219\uff1a<\/strong>\u786e\u4fdd\u9632\u706b\u5899\u6ca1\u6709\u963b\u6b62\u5bf9\u8bf7\u6c42\u8d44\u6e90\u7684\u8bbf\u95ee\u3002<\/li>\n<li> <strong>SELinux \u8bbe\u7f6e\uff1a<\/strong>\u5982\u679c\u542f\u7528\u4e86 SELinux\uff0c\u5219\u53ef\u80fd\u9700\u8981\u8c03\u6574\u8bbe\u7f6e\u4ee5\u5141\u8bb8\u8bbf\u95ee\u8d44\u6e90\u3002<\/li>\n<li> <strong>\u5e94\u7528\u7a0b\u5e8f\u95ee\u9898\uff1a<\/strong>\u5982\u679c Nginx \u53ea\u662f\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\uff0c\u5219\u95ee\u9898\u53ef\u80fd\u51fa\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002\u68c0\u67e5\u5e94\u7528\u7a0b\u5e8f\u7684\u65e5\u5fd7\u4ee5\u67e5\u627e\u4efb\u4f55\u9519\u8bef\u6d88\u606f\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f403\u600e\u4e48\u89e3\u51b3\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3 nginx 403 forbidden \u9519\u8bef\uff1f\u68c0\u67e5\u6587\u4ef6\u6216\u76ee\u5f55\u6743\u9650\uff1b2. \u68c0\u67e5 .htaccess \u6587\u4ef6\uff1b3. \u68c0\u67e5 nginx \u914d\u7f6e\u6587\u4ef6\uff1b4. \u91cd\u542f nginx\u3002\u5176\u4ed6\u53ef\u80fd\u539f\u56e0\u8fd8\u5305\u62ec\u9632\u706b\u5899\u89c4\u5219\u3001selinux \u8bbe\u7f6e\u6216\u5e94\u7528\u7a0b\u5e8f\u95ee\u9898\u3002 \u5982\u4f55\u89e3\u51b3 Nginx 403 Forbidden \u9519\u8bef \u5f00\u95e8\u89c1\u5c71\u7684\u56de\u7b54\uff1a Nginx 403 Forbidden \u9519\u8bef\u8868\u793a\u5ba2\u6237\u7aef\u6ca1\u6709\u6743\u9650\u8bbf\u95ee\u8bf7\u6c42\u7684\u8d44\u6e90\u3002\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u5e38\u89c1\u6b65\u9aa4\u5305\u62ec\uff1a \u8be6\u7ec6\u5c55\u5f00\u56de\u7b54\uff1a 1. \u68c0\u67e5\u6587\u4ef6\u6216\u76ee\u5f55\u6743\u9650\uff1a \u786e\u4fdd\u8bf7\u6c42\u7684\u8d44\u6e90\u5177\u6709\u9002\u5f53\u7684\u6587\u4ef6\u6216\u76ee\u5f55\u6743\u9650\u3002\u901a\u5e38\uff0c\u670d\u52a1\u5668\u5e94\u5177\u6709\u8bfb\u53d6\u548c\u6267\u884c\u6743\u9650\uff0c\u800c\u7528\u6237\u5e94\u4ec5\u5177\u6709\u8bfb\u53d6\u6743\u9650\u3002 \u4f7f\u7528 ls -l \u547d\u4ee4\u68c0\u67e5\u6587\u4ef6\u6216\u76ee\u5f55\u7684\u6743\u9650\uff0c\u5e76\u6839\u636e\u9700\u8981\u4f7f\u7528 chmod \u547d\u4ee4\u8c03\u6574\u5b83\u4eec\u3002 2. \u68c0\u67e5 .ht \u6587\u4ef6\uff1a .htaccess \u6587\u4ef6\u53ef\u80fd\u5305\u542b\u9650\u5236\u8bbf\u95ee\u7684\u89c4\u5219\u3002\u68c0\u67e5\u6587\u4ef6\u662f\u5426\u5b58\u5728\uff0c\u5e76\u786e\u4fdd\u5b83\u4e0d\u5305\u542b\u62d2\u7edd\u8bbf\u95ee\u8bf7\u6c42\u7684\u89c4\u5219\u3002 3. \u68c0\u67e5 Nginx \u914d\u7f6e\u6587\u4ef6\uff1a \u6253\u5f00 Nginx \u914d\u7f6e\u6587\u4ef6 (\/etc\/\/nginx.conf \u6216 \/usr\/local\/etc\/nginx\/nginx.conf) \u5e76\u68c0\u67e5\u4ee5\u4e0b\u5757\uff1a location \/ { # [&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-18050","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18050","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=18050"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18050\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}