{"id":69,"date":"2023-12-12T17:30:44","date_gmt":"2023-12-12T09:30:44","guid":{"rendered":"http:\/\/www.woniuseo.com\/wordpress\/?p=69"},"modified":"2023-12-14T17:59:04","modified_gmt":"2023-12-14T09:59:04","slug":"nginx%e4%ba%8c%e7%ba%a7%e7%9b%ae%e5%bd%95%e7%ab%99%ef%bc%88%e5%ad%90%e7%9b%ae%e5%bd%95%ef%bc%89%e4%bc%aa%e9%9d%99%e6%80%81%e8%ae%be%e7%bd%ae%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.woniuseo.com\/wordpress\/daima\/69.html","title":{"rendered":"Nginx\u4e8c\u7ea7\u76ee\u5f55\u7ad9\uff08\u5b50\u76ee\u5f55\uff09\u4f2a\u9759\u6001\u8bbe\u7f6e\u65b9\u6cd5"},"content":{"rendered":"
\u6709\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u5728\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u9762\u518d\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ea7\u76ee\u5f55\u7ad9\uff0c\u4e5f\u5c31\u662f\u5b50\u76ee\u5f55\u7684\u7ad9\u70b9\uff0c\u5982\u679c\u8fd9\u4eec\u7684\u8bdd\uff0c\u6211\u4eec\u5c31\u9700\u8981\u91cd\u65b0\u53bb\u7ed9\u4e8c\u7ea7\u76ee\u5f55\u7ad9\uff08\u5b50\u76ee\u5f55\uff09\u505a\u4f2a\u9759\u6001\u4e86\u3002\u5177\u4f53\u64cd\u4f5c\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n
<\/p>\n
\u4e3a\u4e86\u66f4\u597d\u7684\u793a\u4f8b\uff0c\u8fd9\u91cc\u4ee5 WordPress \u7a0b\u5e8f\u642d\u5efa\u4e8c\u7ea7\u76ee\u5f55\u7ad9\u4e3a\u6d4b\u8bd5\u3002<\/p>\n
<\/p>\n
<\/p>\n
1\u3001\u53ea\u9700\u8981\u6dfb\u52a0\u8fd9\u4e2a\u4e8c\u7ea7\u76ee\u5f55\u7684\u4f2a\u9759\u6001\u5c31\u53ef\u4ee5\u4e86\uff0c\u8fd9\u91cc\u4ee5LNMP\u73af\u5883\u7684 nginx.conf \u914d\u7f6e\u6587\u4ef6\u4e3a\u4f8b\u5b50\uff1b<\/p>\n
\u53ea\u9700\u8981\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a\u201dfujieace\u201d\u8bf7\u66ff\u6362\u6210\u4f60\u81ea\u5df1\u7684\u4e8c\u7ea7\u7f51\u7ad9\u76ee\u5f55\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n
location \/fujieace\/ {\r\n\u3000\u3000index<\/span> index<\/span>.html index<\/span>.php;\r\n\u3000\u3000if<\/span> (-f $request_filename\/index<\/span>.html){\r\n\u3000\u3000rewrite (.*) $1\/index<\/span>.html break<\/span>;\r\n\u3000\u3000}\r\n\r\n\u3000\u3000if<\/span> (-f $request_filename\/index<\/span>.php){\r\n\u3000\u3000rewrite (.*) $1\/index<\/span>.php;\r\n\u3000\u3000}\r\n\r\n\u3000\u3000if<\/span> (!-f $request_filename){\r\n\u3000\u3000rewrite (.*) \/fujieace\/index<\/span>.php;\r\n\u3000\u3000}\r\n\u3000\u3000}<\/code><\/pre>\n <\/p>\n
2\u3001\u91cd\u542fnginx\uff1b<\/p>\n
<\/p>\n
\u6ce8\u610f\uff1a<\/p>\n
LNMP\u7684Nginx\u4e0b\u9762\u4e5f\u6709\u5f88\u591a\u7c7b\u4f3c\u7684\u4f2a\u9759\u6001\u914d\u7f6e\u6587\u4ef6\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u76f4\u63a5 include \u6709\u5f15\u5165\u3002<\/p>\n
\u4f8b\u5982\uff1awordpress.conf\u3001wp2.conf\u3001dedecms.conf\u3001discuz.conf \u3001ecshop.conf\u2026\u2026\u7b49\u7b49\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n
<\/p>\n
<\/p>\n
\u4e8c\u3001\u5b9d\u5854\u9762\u677f\uff1aNginx\u4e8c\u7ea7\u76ee\u5f55\u4f2a\u9759\u6001<\/h2>\n
\u6ce8\u610f\uff1a<\/p>\n
\u5982\u679c\u4f60\u7528\u7684\u662f\u5b9d\u5854\u9762\u677f\uff0c\u4f60\u7528\u7b2c\u4e00\u79cd\u4e0a\u9762\u7684\u4f2a\u9759\u6001\u89c4\u5219\uff0c\u662f\u4f1a\u62a5\u7c7b\u4f3c\u5982\u4e0b\u8fd9\u6837\u7684\u9519\u8bef\uff1a<\/p>\n
nginx: [emerg] unknown directive \u201c\u3000\u3000index\u201d in<\/p>\n
\/www\/server\/panel\/vhost\/rewrite\/www.xxx.com.conf:7<\/p>\n
nginx: configuration file \/www\/server\/nginx\/conf\/nginx.conf test failed<\/p><\/blockquote>\n
\u4e2d\u6587\u7ffb\u8bd1<\/p>\n
nginx\uff1a[emerg]\u672a\u77e5\u6307\u4ee4\u201cindex\u201d\u5728<\/p>\n
\/www\/server\/panel\/vhost\/rewrite\/www.xxx.com.conf:7<\/p>\n
nginx\uff1a\u914d\u7f6e\u6587\u4ef6\/www\/server\/nginx\/conf\/nginx.conf\u6d4b\u8bd5\u5931\u8d25<\/p><\/blockquote>\n
<\/p>\n
<\/p>\n
\u5982\u679c\u4f60\u7528\u7684\u662f\u5b9d\u5854\u9762\u677f\uff0c\u4f60\u7684\u4f2a\u9759\u6001\u53ea\u9700\u8981\u76f4\u63a5\u9009\u62e9\u201cwp2<\/strong>\u201c\u5373\u53ef\uff01<\/p>\n\u8fd9\u91cc\u5f88\u591a\u4eba\u6216\u8bb8\u4f1a\u6709\u7591\u95ee\uff1f\u5b9d\u5854\u4f2a\u9759\u6001wordpress\u4e0ewp2\u7684\u533a\u522b\u662f\u4ec0\u4e48\uff1f\u7b54\u6848\u662f\uff1awordpress \u662f\u6807\u51c6\u7684\u4f2a\u9759\u6001\uff0cwp2 \u662f\u4ee3\u8868\u7684\u628a WordPress \u88c5\u5728\u5b50\u76ee\u5f55\u7684\u4f2a\u9759\u6001\u3002<\/p>\n
<\/p>\n
<\/p>\n
rewrite<\/span> ^.*\/files\/(.*)$<\/span> \/wp-includes\/ms-files.php?file=$1<\/span> last<\/span>;\r\nif<\/span> (!-e $request_filename<\/span>){\r\n\trewrite<\/span> ^.+?(\/wp-.*)<\/span> $1<\/span> last<\/span>;\r\n\trewrite<\/span> ^.+?(\/.*\\.php)$<\/span> $1<\/span> last<\/span>;\r\n\trewrite<\/span> ^<\/span> \/index.php last<\/span>;\r\n}<\/code><\/pre>\n <\/p>\n
\u4e09\u3001Nginx try_files\u5b9e\u73b0\u4e8c\u7ea7\u76ee\u5f55\u4f2a\u9759\u6001<\/h2>\n
\u5f53\u7136\uff0c\u4e5f\u53ef\u4ee5\u7528\u4ee5\u4e0b\u4ee3\u7801\u5b9e\u73b0\u4f2a\u9759\u6001\u3002\u81f3\u4e8e try_files \u548c rewrite \u54ea\u4e2a\u6548\u7387\u66f4\u9ad8\uff1f\u76ee\u524d\u4e0d\u5f97\u800c\u77e5\uff0c\u9700\u8981\u505a\u8fdb\u4e00\u6b65\u7684\u4e86\u89e3\u3002<\/p>\n
location<\/span> \/fujieace\/ {\r\n index<\/span> index.php;\r\n try_files<\/span> $uri<\/span> $uri<\/span>\/ \/fujieace\/index.php?$args<\/span>;\r\n}<\/code><\/pre>\n\u6216\u8005<\/p>\n
\u53ef\u4ee5\u76f4\u63a5\u91c7\u7528 LNMP \u7a0b\u5e8f\u4e0b\u7684\u914d\u7f6e\u6587\u4ef6\uff1awp2.conf\uff1b<\/p>\n
location \/cmp\/ {\r\n try_files $uri $uri\/ \/cmp\/index<\/span>.php?$args;\r\n}\r\n\r\n# Add trailing slash to *\/wp-admin requests.<\/span>\r\nrewrite \/wp-admin$ $scheme:\/\/<\/span>$host$uri\/ permanent;<\/code><\/pre>\n <\/p>\n
\u603b\u7ed3\uff1a<\/p>\n
\u6709\u4e00\u70b9\u5927\u5bb6\u9700\u8981\u6ce8\u610f\uff0c\u73b0\u5728nginx\u914d\u7f6e\u5206\u4e3a http \u548c https\u4e24\u4e2a\u5730\u65b9\uff0c\u6709\u65f6\u5019\u5f88\u591a\u4eba\u628a \u914d\u7f6e\u4f2a\u9759\u6001\u89c4\u5219 \u653e\u5728\u7684\u662f http server\u4e2d\u7684\uff0c\u7ed3\u679c https server\u4e2d\u5374\u5fd8\u8bb0\u4e86\u914d\u7f6e\uff0c\u6070\u597d\u4ed6\u7684\u7f51\u7ad9\u53c8\u662f\u4ee5https\u4e3a\u4e3b\u7684\uff0c\u8fd9\u6837\u7684\u8bdd\uff0c\u4f1a\u9020\u6210\u5c31\u7b97\u4f60\u91cd\u65b0\u52a0\u8f7d\u4e86nginx\u914d\u7f6e\u540e\uff0c\u4f2a\u9759\u6001\u89c4\u5219\u5374\u4e0d\u4f1a\u751f\u6548\u3002<\/p>\n
<\/p>\n
\u6211\u7684\u5efa\u8bae\u662f\uff1a<\/p>\n
\u53ea\u8981\u4f60\u7684\u7f51\u7ad9\u652f\u6301HTTPS\uff0c\u5efa\u8bae\u5927\u5bb6\u6bcf\u6b21\u914d\u7f6e\u4f2a\u9759\u6001\u89c4\u5219\u4e00\u5b9a\u8981\u53bb http server \u548c\u00a0 https server\u4e24\u4e2a\u5730\u65b9\u90fd\u6dfb\u52a0\u4e0a\u4f2a\u9759\u6001\u89c4\u5219\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"
\u6709\u65f6\u5019\uff0c\u6211\u4eec\u53ef\u80fd\u4f1a\u5728\u7f51\u7ad9\u6839\u76ee\u5f55\u4e0b\u9762\u518d\u521b\u5efa\u4e00\u4e2a\u4e8c\u7ea7\u76ee\u5f55\u7ad9\uff0c\u4e5f\u5c31\u662f\u5b50\u76ee\u5f55\u7684\u7ad9\u70b9\uff0c\u5982\u679c\u8fd9\u4eec\u7684\u8bdd\uff0c\u6211\u4eec\u5c31\u9700\u8981\u91cd\u65b0\u53bb\u7ed9\u4e8c […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3252],"tags":[],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-daima"],"_links":{"self":[{"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":1,"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":70,"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/posts\/69\/revisions\/70"}],"wp:attachment":[{"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.woniuseo.com\/wordpress\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}