{"id":124401,"date":"2018-10-17T08:55:46","date_gmt":"2018-10-17T00:55:46","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=124401"},"modified":"2018-10-16T08:56:18","modified_gmt":"2018-10-16T00:56:18","slug":"nginx-403-forbidden","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/nginx-403-forbidden.html","title":{"rendered":"\u56db\u79cd\u89e3\u51b3Nginx\u51fa\u73b0403 forbidden \u62a5\u9519\u7684\u65b9\u6cd5"},"content":{"rendered":"
\u6211\u662f\u5728\u5728\u672c\u5730\u7528\u865a\u62df\u673a\u4e2d\u901a\u8fc7yum\u5b89\u88c5nginx\u7684\uff0c\u5b89\u88c5\u4e00\u5207\u6b63\u5e38\uff0c\u4f46\u662f\u8bbf\u95ee\u65f6\u62a5403\uff0c<\/p>\n
\u4e8e\u662f\u67e5\u770bnginx\u65e5\u5fd7\uff0c\u8def\u5f84\u4e3a\/var\/log\/nginx\/error.log\u3002\u6253\u5f00\u65e5\u5fd7\u53d1\u73b0\u62a5\u9519Permission denied\uff0c\u8be6\u7ec6\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n
1.\u00a0\u00a0\u00a0\u00a0open()\u00a0\"\/data\/www\/1.txt\"\u00a0failed\u00a0(13:\u00a0Permission\u00a0denied),\u00a0client:\u00a0192.168.1.194,\u00a0server:\u00a0www.web1.com,\u00a0request:\u00a0\"GET\u00a0\/1.txt\u00a0HTTP\/1.1\",\u00a0host:\u00a0\"www.web1.com\"\r\n<\/pre>\n\u6ca1\u6709\u6743\u9650\uff1f\u4e8e\u662f\u627e\u4e86\u4e0d\u5c11\u8d44\u6599\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e0b\u9762\u56db\u6b65\u6392\u67e5\u89e3\u51b3\u6b64\u95ee\u9898\u3002\u4f60\u53ef\u80fd\u53ea\u662f\u5176\u4e2d\u4e4b\u524d\u914d\u7f6e\u6709\u95ee\u9898\uff0c\u4e0d\u4e00\u5b9a\u56db\u4e2a\u6b65\u9aa4\u90fd\u7528\u4e0a\u3002<\/p>\n
\u4e00\u3001\u7531\u4e8e\u542f\u52a8\u7528\u6237\u548cnginx\u5de5\u4f5c\u7528\u6237\u4e0d\u4e00\u81f4\u6240\u81f4<\/strong><\/span><\/div>\n1.1\u67e5\u770bnginx\u7684\u542f\u52a8\u7528\u6237\uff0c\u53d1\u73b0\u662fnobody\uff0c\u800c\u4e3a\u662f\u7528root\u542f\u52a8\u7684<\/p>\n
\u547d\u4ee4\uff1aps aux | grep \"nginx: worker process\" | awk'{print $1}'<\/pre>\n1.2\u5c06nginx.config\u7684user\u6539\u4e3a\u548c\u542f\u52a8\u7528\u6237\u4e00\u81f4\uff0c<\/p>\n
\u547d\u4ee4\uff1avi conf\/nginx.conf<\/p>\n
\u4e8c\u3001\u7f3a\u5c11index.html\u6216\u8005index.php\u6587\u4ef6\uff0c\u5c31\u662f\u914d\u7f6e\u6587\u4ef6\u4e2dindex index.html index.htm\u8fd9\u884c\u4e2d\u7684\u6307\u5b9a\u7684\u6587\u4ef6\u3002<\/strong><\/span><\/div>\n1.\u00a0\u00a0\u00a0\u00a0server\u00a0{\r\n2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0listen\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a080;\r\n3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0server_name\u00a0\u00a0localhost;\r\n4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0index\u00a0\u00a0index.php\u00a0index.html;\r\n5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0root\u00a0\u00a0\/data\/www\/;\r\n6.\u00a0\u00a0\u00a0\u00a0}\r\n<\/pre>\n\u5982\u679c\u5728\/data\/www\/\u4e0b\u9762\u6ca1\u6709index.php,index.html\u7684\u65f6\u5019\uff0c\u76f4\u63a5\u6587\u4ef6\uff0c\u4f1a\u62a5403 forbidden\u3002<\/p>\n
\u4e09\u3001\u6743\u9650\u95ee\u9898\uff0c\u5982\u679cnginx\u6ca1\u6709web\u76ee\u5f55\u7684\u64cd\u4f5c\u6743\u9650\uff0c\u4e5f\u4f1a\u51fa\u73b0403\u9519\u8bef\u3002<\/strong><\/span><\/div>\n\u89e3\u51b3\u529e\u6cd5\uff1a\u4fee\u6539web\u76ee\u5f55\u7684\u8bfb\u5199\u6743\u9650\uff0c\u6216\u8005\u662f\u628anginx\u7684\u542f\u52a8\u7528\u6237\u6539\u6210\u76ee\u5f55\u7684\u6240\u5c5e\u7528\u6237\uff0c\u91cd\u542fNginx\u5373\u53ef\u89e3\u51b3<\/p>\n
1.\u00a0\u00a0\u00a0\u00a0chmod\u00a0-R\u00a0777\u00a0\/data\r\n2.\u00a0\u00a0\u00a0\u00a0chmod\u00a0-R\u00a0777\u00a0\/data\/www\/\r\n<\/pre>\n\u56db\u3001SELinux\u8bbe\u7f6e\u4e3a\u5f00\u542f\u72b6\u6001\uff08enabled\uff09\u7684\u539f\u56e0\u3002<\/strong><\/span><\/div>\n4.1\u3001\u67e5\u770b\u5f53\u524dselinux\u7684\u72b6\u6001\u3002<\/p>\n
1.\u00a0\u00a0\u00a0\u00a0\/usr\/sbin\/sestatus\r\n<\/pre>\n4.2\u3001\u5c06SELINUX=enforcing\u00a0\u4fee\u6539\u4e3a\u00a0SELINUX=disabled\u00a0\u72b6\u6001\u3002<\/p>\n
1.\u00a0\u00a0\u00a0\u00a0vi\u00a0\/etc\/selinux\/config\r\n2.\r\n3.\u00a0\u00a0\u00a0\u00a0#SELINUX=enforcing\r\n4.\u00a0\u00a0\u00a0\u00a0SELINUX=disabled\r\n<\/pre>\n4.3\u3001\u91cd\u542f\u751f\u6548\u3002reboot\u3002<\/p>\n
1.\u00a0\u00a0\u00a0\u00a0reboot<\/pre>\n---------------------<\/p>\n","protected":false},"excerpt":{"rendered":"
\u6211\u662f\u5728\u5728\u672c\u5730\u7528\u865a\u62df\u673a\u4e2d\u901a\u8fc7yum\u5b89\u88c5nginx\u7684\uff0c\u5b89\u88c5\u4e00\u5207\u6b63\u5e38\uff0c\u4f46\u662f\u8bbf\u95ee\u65f6\u62a5403\uff0c \u4e8e\u662f\u67e5\u770bnginx\u65e5\u5fd7\uff0c […]<\/p>\n","protected":false},"author":643,"featured_media":124402,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-124401","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/124401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/643"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=124401"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/124401\/revisions"}],"predecessor-version":[{"id":124406,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/124401\/revisions\/124406"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/124402"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=124401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=124401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=124401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}