{"id":512186,"date":"2021-06-12T21:22:28","date_gmt":"2021-06-12T13:22:28","guid":{"rendered":"http:\/\/4563.org\/?p=512186"},"modified":"2021-06-12T21:22:28","modified_gmt":"2021-06-12T13:22:28","slug":"%e6%b1%82%e6%95%99-nginx-%e5%86%85%e6%97%a0%e6%b3%95%e4%bd%bf%e7%94%a8-include-%e8%b0%83%e7%94%a8%e5%90%ab%e6%9c%89-if-%e7%9a%84%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=512186","title":{"rendered":"\u6c42\u6559 nginx \u5185\u65e0\u6cd5\u4f7f\u7528 include \u8c03\u7528\u542b\u6709 if \u7684\u914d\u7f6e?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1> \u6c42\u6559 nginx \u5185\u65e0\u6cd5\u4f7f\u7528 include \u8c03\u7528\u542b\u6709 if \u7684\u914d\u7f6e? <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : stille <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5206\u522b\u5728 docker nginx \u548c yum install nginx \u4e24\u4e2a\u73af\u5883\u4e0b\u6d4b\u8bd5\u90fd\u62a5\u9519.<\/p>\n<p>\u5728 conf.d \u5185\u521b\u5efa\u4e86\u57df\u540d xxx.com.conf \u5e76\u5728\u914d\u7f6e\u4e2d\u4f7f\u7528\u4e86 if \u8bed\u53e5,<strong>\u6d4b\u8bd5\u901a\u8fc7,reload \u540e\u4e5f\u751f\u6548<\/strong>.<\/p>\n<p>\u4f46\u662f,\u5f53\u5728 conf.d \u521b\u5efa 2.conf ,\u5c06 if \u8bed\u53e5\u653e\u5728\u8fd9\u91cc.<br \/> \u5e76\u5728 xxx.com.conf \u4e2d include conf.d\/2.conf; \u6d4b\u8bd5\u5747\u62a5\u9519<\/p>\n<pre><code>nginx: [emerg] \"if\" directive is not allowed here in \/etc\/nginx\/conf.d\/2.conf:1 nginx: configuration file \/etc\/nginx\/nginx.conf test failed <\/code><\/pre>\n<p><strong>\u5947\u602a\u7684\u662f<\/strong> \u4f7f\u7528\u519b\u54e5 LNMP.org \u5b89\u88c5\u7684\u73af\u5883\u5374\u6210\u529f\u4e86.<\/p>\n<p>\u6c42\u6559\u5927\u795e\u662f\u5426\u662f\u4ec0\u4e48\u6a21\u5757\u9700\u8981\u7f16\u8bd1\u5b89\u88c5\u8fd8\u662f\u8bf4\u6709\u5176\u4ed6\u914d\u7f6e?<\/p>\n<p>if \u8bed\u53e5\u5c31\u662f\u7b80\u5355\u7684\u6b63\u5219\u8fc7\u6ee4.<\/p>\n<pre><code>    if ($request_uri ~* \"(aaa|bbb|cdf|223|sasss)\") {         return 301 https:\/\/xxxx.com$request_uri;     } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>) <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"6039147\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : eason1874 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> \u6709 if \u53ef\u4ee5 include<br \/>\u4f60\u7684\u95ee\u9898\u5e94\u8be5\u662f\u5728 nginx.conf \u5199\u4e86 include conf.d\/*.conf; <br \/>\u6240\u4ee5 2.conf \u4e0d\u4ec5\u88ab xxx.com.conf \u8f7d\u5165\u4e86\uff0c\u4e5f\u88ab nginx.conf http \u8f7d\u5165\u4e86\uff0c\u800c http \u6bb5\u662f\u4e0d\u652f\u6301 if \u7684 <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"6039148\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : stille <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @eason1874 \u5662,\u611f\u8c22\u56de\u590d,\u90a3\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u662f\u6362\u4e2a\u76ee\u5f55\u653e\u8fd9\u4e2a 2.conf \u5427,\u53ea\u8981\u4e0d\u662f nginx.conf include \u7684\u5230\u5c31\u884c&#8230;\u7136\u540e\u5355\u72ec\u7ed9\u57df\u540d.conf include \u5230\u5c31\u884c <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"6039149\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : stille <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>  <\/span> <\/div>\n<\/p><\/div>\n<div> @eason1874 \u8c22\u8c22.\u6d4b\u8bd5\u6210\u529f\u4e86&#8230; <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u6c42\u6559 nginx \u5185\u65e0\u6cd5\u4f7f\u7528 in&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/512186"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=512186"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/512186\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=512186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=512186"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=512186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}