最新消息:重新回归WordPress,我要比较认真的开始更新我的博客了。

通过HTTP访问HTTPS页面出错问题

服务器相关 hanlei 131浏览

用npm做代理并配置了SSL证书,这时候输网址如果不写前面的HTTPS就会默认用HTTP打开页面,然后就会报错“The plain HTTP request was sent to HTTPS port”。

为了更快、更方便的打开页面,需要把这个错误页面重定向到正确的地址。配置如下。

server {
    listen 1334 ssl;
    server_name domain.com;
    error_page 497 https://$host:1334$uri?args;
    location / {
       ......
    }
}

如果80端口也在使用可以将http请求重定向到https

server {
    listen 80;
    listen 1443 ssl;
    server_name domain.com;
    if ($scheme = http) {
        return 301 https://$host:1334$uri?args;
    }
    location / {
       ......
    }
}

转载请注明:HANLEI'BLOG » 通过HTTP访问HTTPS页面出错问题