{"id":197525,"date":"2020-11-02T01:32:38","date_gmt":"2020-11-01T17:32:38","guid":{"rendered":"http:\/\/4563.org\/?p=197525"},"modified":"2020-11-02T01:32:38","modified_gmt":"2020-11-01T17:32:38","slug":"%e9%97%ae%e4%b8%aa-nginx-%e9%85%8d%e7%bd%ae%e9%87%8c%e9%9d%a2%e7%9a%84-%e5%9f%9f%e5%90%8d%e8%b7%b3%e8%bd%ac-301-%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=197525","title":{"rendered":"\u95ee\u4e2a nginx \u914d\u7f6e\u91cc\u9762\u7684 \u57df\u540d\u8df3\u8f6c 301 \u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u95ee\u4e2a nginx \u914d\u7f6e\u91cc\u9762\u7684 \u57df\u540d\u8df3\u8f6c 301 \u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : python30 <\/span>  <span><i><\/i> 8<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u95ee\u4e2a nginx \u914d\u7f6e\u91cc\u9762\u7684 \u57df\u540d\u8df3\u8f6c 301 \u95ee\u9898<\/p>\n<p>\u60f3\u628a www.qqq.com \u5168\u90e8\u6c38\u4e45 301 \u91cd\u5b9a\u5411\u5230 www.aaa.com \u4e0b\u9762\u662f\u6211\u7684 nginx \u91cc\u9762\u7684\u914d\u7f6e\u3002\u6211\u4e0b\u9762\u7684\u4ee3\u7801\u4e0d\u6210\u529f\u3002\u4e0d\u77e5\u9053\u6b63\u786e\u7684\u600e\u4e48\u5b9e\u73b0\u5462\uff1f<\/p>\n<pre><code>server {         listen 443 ssl;         server_name www.qqq.com qqq.com;         ssl_certificate 1_www.qqq.com_bundle.crt;         ssl_certificate_key 2_www.qqq.com.key;         ssl_session_timeout 5m;         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;         ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;         ssl_prefer_server_ciphers on;         charset UTF-8;          client_max_body_size 75M;         fastcgi_buffers   8 128k;         fastcgi_busy_buffers_size 128k;           location \/ {                 include uwsgi_params;                 uwsgi_pass 127.0.0.1:12008;                 uwsgi_send_timeout 300;                 uwsgi_connect_timeout 300;                 uwsgi_read_timeout 300;         }         location \/static {                 expires 30d;                 autoindex on;                 #return 403;                 add_header Cache-Control private;                 alias \/www\/www\/html\/qqq\/static\/;         }         location \/media {                 expires 30d;                 autoindex on;                 #return 403;                 add_header Cache-Control private;                 alias \/www\/www\/html\/qqq\/media\/;         }    }  erver{         listen 80;         server_name www.qqq.com qqq.com;         rewrite ^(.*) https:\/\/www.aaa.com$1 permanent;     } <\/code><\/pre>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>10<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4236020\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Yakir <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             rewrite ^(.*) https:\/\/www.aaa.com$1 permanent; \u6539\u6210 rewrite ^\/(.*) https:\/\/www.aaa.com\/$1 permanent; \u8bd5\u4e0b<br \/>\u53e6\u5916\u7b2c\u4e8c\u4e2a server \u5c11\u4e86\u4e00\u4e2a s\uff0c\u786e\u5b9a reload \u6ca1\u6709\u62a5\u9519\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236021\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dorothyREN <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u76f4\u63a5 return 301 www.aaa.com                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236022\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : python30 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yakir \u786e\u5b9e\u662f \u90a3\u4e2a server \u5c11\u4e86\u4e2a s \u7684\u95ee\u9898\u3002\u73b0\u5728\u80fd\u8df3\u4e86<br \/>\u8fd8\u6709\u5c31\u662f\u600e\u4e48\u8bbe\u7f6e https \u4e5f\u4e00\u8d77\u8df3\uff1f<br \/>\u73b0\u5728\u53ea\u80fd http \u7684\u8df3\u8fc7\u53bb\u3002https \u8fd8\u662f\u539f\u6765\u7684\u7f51\u5740<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u95ee\u9898\u3002\u6211\u4ee5\u524d\u597d\u50cf\u8bbe\u7f6e\u8fc7\u3002\u8bb0\u5f97 rewrite 301 \u4ec0\u4e48\u7684<br \/>\u4e0d\u77e5\u9053\u8fd9\u4e2a\u4e0a\u9762\u8fd9\u6837\u662f\u4e0d\u662f\u6c38\u4e45 301 \u91cd\u5b9a\u5411\u7684\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236023\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : python30 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dorothyREN <br \/>\u4e0d\u53ea\u662f\u53ea\u6709\u4e3b\u57df\u540d\u3002\u8fd8\u6709\u91cc\u9762\u7684\u4e00\u4e9b\u76ee\u5f55\u4e5f\u4e00\u8d77\u8df3\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236024\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : python30 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yakir <br \/>\u8fd9\u6837\u5199\u8fd8\u6709\u4e2a\u95ee\u9898<br \/>\u5c31\u662f\u76ee\u5f55\u8df3\u8f6c\u7684\u65f6\u5019 \u5c11\u4e86\u4e2a \/<br \/>\u6bd4\u5982\uff1awww.qqq.com\/aaa\/bbb \u8df3\u8fc7\u53bb www.aaa.comaaa\/bbb \u5c11\u4e86 com \u540e\u9762\u7684 \/                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236025\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : bin456789 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             if ($http_host = www.qqq.com) {<br \/> return 301 https:\/\/www.aaa.com$request_uri;<br \/> }                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236026\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ysc3839 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Yakir @bin456789 <br \/>\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4e0d\u8981\u7528 if \u4e5f\u4e0d\u8981\u7528 rewrite\uff0cnginx \u5b98\u7f51\u7684 Pitfalls and Common Mistakes \u4e2d\u63d0\u5230\u4e86\u8fd9\u4e24\u4e2a\u95ee\u9898\u3002<br \/>https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/tutorials\/config_pitfalls\/#server-name-if<br \/>https:\/\/www.nginx.com\/resources\/wiki\/start\/topics\/tutorials\/config_pitfalls\/#taxing-rewrites                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236027\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : quanjw <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5206\u4e24\u4e2a server \u76f4\u63a5 301                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236028\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : doveyoung <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             80 \u548c 443 \u7aef\u53e3\u7684\u914d\u7f6e\u4e0b\u9762\u5206\u522b\u90fd\u8981\u6709 301<\/p>\n<p>\u53e6\u5916 nginx \u5b98\u7f51\u5efa\u8bae\u4f7f\u7528 301 \u800c\u4e0d\u662f rewrite\uff0c\u5f53\u7136 rewrite \u4e5f\u53ef\u4ee5                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4236029\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : python30 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u6837\u80fd\u8df3\u8f6c\u4e86\u3002\u5206\u522b\u5728\u4e24\u4e2a server \u91cc\u9762\u6dfb\u52a0\u4e86\uff1a<br \/>return 301 https:\/\/www.aaa.com$request_uri;<\/p>\n<p>\u6d4b\u8bd5\u6b62\u5f55\u4e5f\u80fd\u8df3<br \/>\u8fd9\u6837\u662f\u6c38\u4e45 301 \u5427<br \/>\u4e0d\u77e5\u9053\u5bf9 seo \u6709\u5229\u4e0d<\/p>\n<p>&#8220;`<br \/>server {<br \/> listen 443 ssl;<br \/> server_name www.qqq.com qqq.com;<br \/> ssl_certificate 1_www.qqq.com_bundle.crt;<br \/> ssl_certificate_key 2_www.qqq.com.key;<br \/> ssl_session_timeout 5m;<br \/> ssl_protocols TLSv1 TLSv1.1 TLSv1.2;<br \/> ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;<br \/> ssl_prefer_server_ciphers on;<br \/> charset UTF-8;<\/p>\n<p> client_max_body_size 75M;<br \/> fastcgi_buffers 8 128k;<br \/> fastcgi_busy_buffers_size 128k;<\/p>\n<p> return 301 https:\/\/www.aaa.com$request_uri;<\/p>\n<p> location \/ {<br \/> include uwsgi_params;<br \/> uwsgi_pass 127.0.0.1:12008;<br \/> uwsgi_send_timeout 300;<br \/> uwsgi_connect_timeout 300;<br \/> uwsgi_read_timeout 300;<br \/> }<br \/> location \/static {<br \/> expires 30d;<br \/> autoindex on;<br \/> #return 403;<br \/> add_header Cache-Control private;<br \/> alias \/www\/www\/html\/qqq\/static\/;<br \/> }<br \/> location \/media {<br \/> expires 30d;<br \/> autoindex on;<br \/> #return 403;<br \/> add_header Cache-Control private;<br \/> alias \/www\/www\/html\/qqq\/media\/;<br \/> }<br \/> }<\/p>\n<p>server{<br \/> listen 80;<br \/> server_name www.qqq.com qqq.com;<br \/> return 301 https:\/\/www.aaa.com$request_uri;<br \/> }<br \/>&#8220;`                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u4e2a nginx \u914d\u7f6e\u91cc\u9762\u7684 \u57df\u540d&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\/197525"}],"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=197525"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/197525\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=197525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=197525"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=197525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}