{"id":340,"date":"2020-08-25T23:22:28","date_gmt":"2020-08-25T15:22:28","guid":{"rendered":"https:\/\/wp.dj47.top\/?p=340"},"modified":"2021-10-20T16:16:17","modified_gmt":"2021-10-20T08:16:17","slug":"lnmp%e7%8e%af%e5%a2%83%e4%b8%8b%e9%85%8d%e7%bd%aessl","status":"publish","type":"post","link":"https:\/\/www.djlog.cn\/?p=340","title":{"rendered":"Nginx\u4eceHTTP\u8df3\u8f6c\u5230HTTPS"},"content":{"rendered":"<h2 id=\"\u4f7f\u7528rewrite\u6307\u4ee4\" style=\"box-sizing: border-box; font-family: verdana, Arial, Helvetica, sans-serif; font-weight: 500; line-height: 1.5; color: #333333; margin: 10px 0px; font-size: 21px; padding: 0px; background-color: #ffffff;\">1\u3001\u4f7f\u7528rewrite\u6307\u4ee4<\/h2>\n<pre class=\"language-javascript\"><code>server {\r\n    listen 80;\r\n    server_name domain.com;\r\n    rewrite ^(.*) https:\/\/$server_name$1 permanent;\r\n     \r\n    #\u6216\r\n    #rewrite ^(.*) https:\/\/www.xxxxx.com$1 permanent;\r\n    #\u6216\r\n    #rewrite ^(.*) https:\/\/$host$1 permanent;\r\n}<\/code><\/pre>\n<h2 id=\"\u4f7f\u7528return\u6307\u4ee4\" style=\"box-sizing: border-box; font-family: verdana, Arial, Helvetica, sans-serif; font-weight: 500; line-height: 1.5; color: #333333; margin: 10px 0px; font-size: 21px; padding: 0px; background-color: #ffffff;\">2\u3001\u4f7f\u7528return\u6307\u4ee4<\/h2>\n<pre class=\"language-javascript\"><code>server {\r\n    listen 80;\r\n     \r\n    #\u5e38\u89c1\u7684301\u8df3\u8f6c\u8bbe\u7f6e3\u79cd\u65b9\u6cd5\r\n    server_name domain.com;\r\n    return 301 https:\/\/$server_name$request_uri;\r\n     \r\n    #if ($scheme = http ) {\r\n    #    return 301 https:\/\/$host$request_uri;\r\n    #}\r\n     \r\n    #if ($server_port = 80 ) {\r\n    #    return 301 https:\/\/$host$request_uri;\r\n    #}\r\n     \r\n}<\/code><\/pre>\n<h2 id=\"\u4f7f\u7528error_page\u6307\u4ee4\" style=\"box-sizing: border-box; font-family: verdana, Arial, Helvetica, sans-serif; font-weight: 500; line-height: 1.5; color: #333333; margin: 10px 0px; font-size: 21px; padding: 0px; background-color: #ffffff;\">3\u3001\u4f7f\u7528error_page\u6307\u4ee4<\/h2>\n<pre class=\"language-javascript\"><code>server {\r\n    listen 80;\r\n    listen 443 ssl;\r\n    server_name domain.com;\r\n    ssl on;\r\n    ssl_certificate     \/etc\/nginx\/ssl\/xxxxx.crt; \r\n    ssl_certificate_key \/etc\/nginx\/ssl\/xxxxx.crt;\r\n \r\n    error_page 497 https:\/\/$server_name$request_uri;\r\n}<\/code><\/pre>\n<p style=\"box-sizing: border-box; margin: 0px 0px 10px; color: #333333; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; background-color: #ffffff;\"><span style=\"box-sizing: border-box; color: #ff0000;\"><span style=\"box-sizing: border-box; font-family: verdana, Arial, Helvetica, sans-serif;\">\u4f7f\u7528error_page\u6307\u4ee4\u65f6\uff0c\u5c06http\u548chttps\u7684\u76d1\u542c\u914d\u7f6e\u5199\u5728\u540c\u4e00\u4e2aserver\u5757\u4e2d\uff0c\u5bf9\u5e94\u7684\u5176\u4ed6\u914d\u7f6e\u4e5f\u9700\u8981\u5728\u8be5server\u914d\u7f6e\u5757\u4e2d\u5b8c\u6210\u3002<\/span><br style=\"box-sizing: border-box; margin: 0px; padding: 0px; color: #333333; font-family: verdana, Arial, Helvetica, sans-serif;\" \/><span style=\"box-sizing: border-box; font-family: verdana, Arial, Helvetica, sans-serif;\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6b64\u65f6\u9700\u8981\u5c06<\/span><\/span><code style=\"box-sizing: border-box; margin: 1px 5px; line-height: 1.8; vertical-align: middle; display: inline-block; overflow-x: auto; font-family: 'Courier New', sans-serif !important; font-size: 12px !important; padding: 0px 5px !important; background-color: #f5f5f5 !important; border: 1px solid #cccccc !important;\"><span style=\"box-sizing: border-box; color: #ff0000;\">error_page<\/span><\/code><span style=\"box-sizing: border-box; font-family: verdana, Arial, Helvetica, sans-serif; color: #ff0000;\">\u6307\u4ee4\u8bed\u53e5\u5199\u5728\u6700\u540e\uff0c\u5426\u5219\u4e0d\u80fd\u751f\u6548\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001\u4f7f\u7528rewrite\u6307\u4ee4 server { listen 80; server_name domain.co [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[8],"tags":[40,50],"class_list":["post-340","post","type-post","status-publish","format-standard","hentry","category-8","tag-linux","tag-ssl"],"_links":{"self":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=340"}],"version-history":[{"count":0,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=\/wp\/v2\/posts\/340\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.djlog.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}