Deploying Next.js to IIS with a custom server #13146
-
Hi everyone |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments 20 replies
-
|
Beta Was this translation helpful? Give feedback.
-
@Kudratov how did you handle the port? That is what I am currently stuck on |
Beta Was this translation helpful? Give feedback.
-
Hi, I think we need clarification on this. I also encountered similar and I've seen that the webpack-hmr still runs in production. Server: IIS via iisnode In package.json file:
In server.js:
In web.config:
This works but there are performance issues as webpack-hmr still runs in production. But if we change the package,json "start": "node server.js" into "start": "next start" then build and run in production, the webpack-hmr won't run (the expected). Is there any way to run "next start" from web.config without going through server.js? |
Beta Was this translation helpful? Give feedback.
-
Also curious about deployment on IIS with next.js I get that its a node.js application but there seems to be a lack of documentation around the setup, seems overtly complicated |
Beta Was this translation helpful? Give feedback.
-
For someone coming here and being frustrated with the approved answer. Here are the config that worked for us
const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
app.prepare().then(() => {
createServer((req, res) => {
const parsedUrl = parse(req.url, true)
handle(req, res, parsedUrl)
}).listen(process.env.PORT || 3000, (err) => {
if (err) throw err
console.log('> Ready on http://localhost')
})
})
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<iisnode loggingEnabled="true" debuggingEnabled="false"/>
<rewrite>
<rules>
<rule name="app" patternSyntax="Wildcard">
<match url="*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration> Make sure you copy the If you run into any issues, usually deleting .next and node_modules folder followed by IIS restart and |
Beta Was this translation helpful? Give feedback.
-
How can i host next on IISNode with SSL? |
Beta Was this translation helpful? Give feedback.
-
If you want to deploy the html export of your next.js site, I've written my experience here. |
Beta Was this translation helpful? Give feedback.
-
This guide helps me to run next start on IIS without needing server.js or next export |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hey guys. You need pm2 commands I run to build and deploy (i use yarn, but you can use npm with npm run
|
Beta Was this translation helpful? Give feedback.
-
If anyone wants the default standalone server to work on newer versions of nextjs (13+) on iisnode, you need remove the This totally fixed it for me. |
Beta Was this translation helpful? Give feedback.
-
I am facing an issue: I have successfully deployed my nextjs project to IIS. It is a subdomain project to let's say www.xyz.com and my project is a sub project called Jam. Now the issue is that , when i am accessing the project through Url: https://xyz.com/Jam then its working fine, but when I do https://www.xyz.com/Jam then it shows an error : Web server is returning an unknown error error code: 520. Below is my web.config file :
</system.webServer> And this is my next.config.mjs file : module.exports = {
}, I cant understand where the problem is, Please Help. |
Beta Was this translation helpful? Give feedback.
next build
and thennext start
should be enough, it's a Node.js application so it's not any different from hosting a Node.js server on IIS