{"id":1705,"date":"2023-03-25T23:04:52","date_gmt":"2023-03-25T15:04:52","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1705"},"modified":"2023-04-23T21:41:11","modified_gmt":"2023-04-23T13:41:11","slug":"nginx-config-http-jump-to-https-access","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/nginx-config-http-jump-to-https-access\/","title":{"rendered":"Nginx\u914d\u7f6ehttp\u8df3\u8f6chttps\u8bbf\u95ee"},"content":{"rendered":"<p>Nginx\u5f3a\u5236http\u8df3\u8f6chttps\u8bbf\u95ee\u6709\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u6cd5<\/p>\n<h2>nginx\u7684rewrite\u65b9\u6cd5<\/h2>\n<p>\u53ef\u4ee5\u628a\u6240\u6709\u7684HTTP\u8bf7\u6c42\u901a\u8fc7rewrite\u91cd\u5199\u5230HTTPS\u4e0a\uff0c\u914d\u7f6e\u65b9\u6cd5\uff1a<\/p>\n<p><!-- more --><\/p>\n<p>\u65b9\u6cd5\u4e00<\/p>\n<pre><code class=\"language-json\">server {\n    listen 80;\n    server_name XXXXX.com;  \/\/\u57df\u540d\n    rewrite ^(.*)$  https:\/\/XXXXXX.com permanent;\n    location ~ \/ {\n        index index.html index.php index.htm;\n    }\n}<\/code><\/pre>\n<p>\u65b9\u6cd5\u4e8c<\/p>\n<pre><code class=\"language-json\">server {\n    listen 80;\n    server_name XXXXX.com;  \/\/\u57df\u540d\n    return 301 https:\/\/$server_name$request_uri;\n    location ~ \/ {\n        index index.html index.php index.htm;\n    }\n}<\/code><\/pre>\n<p>\u65b9\u6cd5\u4e09<\/p>\n<pre><code class=\"language-json\">server {\n    listen 80;\n    server_name XXXXX.com;  \/\/\u57df\u540d\n    rewrite ^(.*)$  https:\/\/$host$1 permanent;\n    location ~ \/ {\n        index index.html index.php index.htm;\n    }\n}<\/code><\/pre>\n<h2>nginx\u7684497\u72b6\u6001\u7801<\/h2>\n<pre><code>497 \u2013 normal request was sent to HTTPS<\/code><\/pre>\n<p>\u5f53\u524d\u7ad9\u70b9\u53ea\u5141\u8bb8HTTPS\u8bbf\u95ee\uff0c\u5f53\u4f7f\u7528HTTP\u8bbf\u95eenginx\u4f1a\u62a5497\u9519\u8bef\u7801<br \/>\n\u53ef\u4ee5\u4f7f\u7528<code>error_page<\/code>\u628a497\u72b6\u6001\u7801\u94fe\u63a5\u91cd\u65b0\u5b9a\u5411\u5230HTTPS\u57df\u540d\u4e0a<\/p>\n<pre><code class=\"language-json\">server {\n    listen 80;\n    server_name XXXXX.com;  \/\/\u57df\u540d\n    error_page 497  https:\/\/$host$uri?$args;\n    location ~ \/ {\n        index index.html index.php index.htm;\n    }\n}<\/code><\/pre>\n<h2>meta\u5237\u65b0\u4f5c\u7528\u5c06http\u8df3\u8f6c\u5230HTTPS<\/h2>\n<p>index.html<\/p>\n<pre><code class=\"language-html\">&lt;html&gt;\n &lt;meta http-equiv=&quot;refresh&quot; content=&quot;0;url=https:\/\/XXXX.com\/&quot;&gt;\n &lt;\/html&gt;<\/code><\/pre>\n<p>nginx\u914d\u7f6e<\/p>\n<pre><code class=\"language-json\">server {\n    listen 80;\n    server_name XXXXX.com;  \/\/\u57df\u540d\n    location ~ \/ {\n    root \/var\/www\/test\/;\n        index index.html index.php index.htm;\n    }\n    error_page 404 https:\/\/xxxx.com\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Nginx\u5f3a\u5236http\u8df3\u8f6chttps\u8bbf\u95ee\u6709\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u6cd5 nginx\u7684rewrite\u65b9\u6cd5 \u53ef\u4ee5\u628a\u6240\u6709\u7684HTTP\u8bf7 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[332],"tags":[323],"class_list":["post-1705","post","type-post","status-publish","format-standard","hentry","category-nginx","tag-https"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1705"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1705\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}