我正在使用以下服务器脚本来运行 http、https 服务器并将所有 http 请求重定向到 https。
当我从 IP 地址本地和远程访问服务器时,请求会重定向到 https,并且 api 会发出不安全的警告。
但是当我通过域访问相同的路由时,我得到了"Site cannot be Reached"错误。
虽然,访问http://example.com/test-route重定向到https://example.com/test-route,我仍然收到Site can't be reached错误。
import http from 'http';
import https from 'https';
import redirectHttps from 'redirect-https';
import greenlock from 'greenlock';
import app from '../app';
var le = greenlock.create({
  server: 'staging', // using https://acme-v01.api.letsencrypt.org/directory in prod
  configDir: 'certs',
  approveDomains: (opts, certs, cb) => {
    if (certs) {
      opts.domains = ['example.com']
    } else {
      opts.email = 'me@mymail.com',
      opts.agreeTos = true;
    }
    cb(null, {
      options: opts,
      certs: certs
    });
  },
});
http.createServer(le.middleware(redirectHttps())).listen(80, function() {
  console.log("Server Running On http @ port " + 80);
});
https.createServer(le.httpsOptions, le.middleware(app)).listen(443, function() {
  console.log("Server Running On https @ port " + 443);
});