如何在 Vue.js 应用程序中设置从 HTTP 到 HTTPS 的重定向?

How to setup redirect from HTTP to HTTPS in Vue.js app?

尝试下面的 nuxt.config.js,但没有任何效果。应用程序只能通过“https”访问,不能通过“http”访问。我做错了什么?

import path from 'path'
import fs from 'fs'
import redirectSSL from 'redirect-ssl'

require('dotenv').config()
const client = require('./plugins/contentful')

export default {
  serverMiddleware: ["redirect-ssl"],
  target: 'server',
  server: {
    host: '0.0.0.0',
    port: 443,
    https: {
      key: fs.readFileSync(path.resolve(__dirname, 'key.pem')),
      cert: fs.readFileSync(path.resolve(__dirname, 'cert.pem'))
    }
  },
      
// some other code there ...
      
}

最好的选择是直接在网络服务器配置中重定向请求 (Nginx / Apache2)

或者你需要第二个 HTTP 服务器监听 80 端口,但我从来没有这样做过 (好吧,我不能在你下面评论 post 因为缺少声誉)