# [Nuxt] Nuxt 3 - local 端開發時使用 HTTPS ###### tags: `Nuxt` :::warning * 若使用自簽憑證(self-signed certificate),需要在 `.env` 內加上 `NODE_TLS_REJECT_UNAUTHORIZED=0`,但專案上線時不可加這個! * 記得將 `server.key` 和 `server.crt` 改成自己的 https 憑證的檔名和存放的路徑 ::: ## 方法一 :::info [官方文件](https://nuxt.com/docs/api/commands/dev) ::: 在 `package.json` 的 `scripts` 加上 `"https": "nuxt dev --https --ssl-cert ./https/server.crt --ssl-key ./https/server.key"`,在終端機輸入 `npm run https` 執行專案 *若不想把 `NODE_TLS_REJECT_UNAUTHORIZED=0` 寫進 `.env` 內,可以直接寫在 `"https"` 裡面,變成 `"https": "NODE_TLS_REJECT_UNAUTHORIZED=0 nuxt dev --https --ssl-cert ./https/localhost+3.pem --ssl-key ./https/localhost+3-key.pem",`* ## 方法二 :::info [官方文件](https://nuxt.com/docs/api/configuration/nuxt-config#https) **Nuxt 3.4 以上才可使用** ::: ```typescript // nuxt.config.ts export default defineNuxtConfig({ devServer: { https: { key: './https/server.key', cert: './https/server.crt', }, }, }); ``` --- :::info 建立日期:2023-08-28 更新日期:2023-08-28 :::
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.