最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

http - How to I deploy nextjs application in a production environment, using ssl? - Stack Overflow

programmeradmin1浏览0评论

There does not seem to be a definitive answer to this. I have seen other questions posted here where people suggest using nginx to proxy ssl and run the next app as http. I've also seen posts about --experimental-https.

My use case: I have nginx setup with ssl. However, I require next to be launched with https for the crypto module to work.

I tried adding --experimental-https to my package.json like such:

  "scripts": {
    "dev": "next dev --turbopack --experimental-https",
    "build": "next build",
    "start": "next start --experimental-https",
    "lint": "next lint",
    "start:dev": "cross-env-shell ./node_modules/.bin/next dev"
  },

Running npm run dev works a charm, enabling ssl support.

Doing a build and running npm run start gives the error:

error: unknown option '--experimental-https'

So how would I actually launch next with https support in a production environment?

There does not seem to be a definitive answer to this. I have seen other questions posted here where people suggest using nginx to proxy ssl and run the next app as http. I've also seen posts about --experimental-https.

My use case: I have nginx setup with ssl. However, I require next to be launched with https for the crypto module to work.

I tried adding --experimental-https to my package.json like such:

  "scripts": {
    "dev": "next dev --turbopack --experimental-https",
    "build": "next build",
    "start": "next start --experimental-https",
    "lint": "next lint",
    "start:dev": "cross-env-shell ./node_modules/.bin/next dev"
  },

Running npm run dev works a charm, enabling ssl support.

Doing a build and running npm run start gives the error:

error: unknown option '--experimental-https'

So how would I actually launch next with https support in a production environment?

Share Improve this question asked Jan 29 at 19:45 Kris RiceKris Rice 8691 gold badge11 silver badges29 bronze badges 4
  • This question is similar to: How can I use an SSL certificate with my Next JS deployment?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. – jabaa Commented Jan 30 at 10:12
  • @jabaa the question goal is the same but the other question did not outline what they had/hadn't tried, which mine does. This covers the answers provided in the supposed "duplicate" question. The goal of this question was to determine if it is possible to actually launch next in production with https using npm run start and not just reverse proxy with nginx. The answers in the question you have provided to not actually answer this question. – Kris Rice Commented Jan 30 at 10:16
  • It implicitly answers it. It's not possible. NextJS doesn't support it. That's why all answers provide different solutions. – jabaa Commented Jan 30 at 10:23
  • @jabaa The other questions imply it is not possible, but do not actually state it as fact. I did not have a definitive answer of whether it was possible or not until you said so in the comments. This is a community. So rather than being unhelpful and just voting it to be closed, perhaps provide an answer to the very fair question I was asking, finally "implicitly" stating it is not possible without the use of a service like nginx. – Kris Rice Commented Feb 1 at 17:22
Add a comment  | 

1 Answer 1

Reset to default -1

So some research has suggested that it is not possible to launch a NextJS app using npm run start with https enabled. It seems it is only possible do do this using --experimental-https in dev mode.

Instead, you have to use a service that supports https like nginx and proxy the results. I had a suspicion of this, but I wanted clarification which I now have.

Just a side note - none of the answers I found (though yes, a solution to the problem) did not explicitly state whether it was possible to do so, which is what my question was was asking. I was not asking how to setup nginx for https with nextjs in production.

发布评论

评论列表(0)

  1. 暂无评论