Deploying Next.js on IIS
Unanswered
timvd7652 posted this in #help-forum
Hi, I have a requirement where I have to deploy a Next.js on IIS. It's my first time deploying to IIS. I've made a small test project to mess around with. I do have a couple results but nothing major.
I've followed some guides on medium that explain the process, like this one: https://medium.com/@dipneupane/deploying-nextjs-application-on-windows-iis-server-cabdc22bccf8
The steps I've taken already to deploy the test project:
- I 've created a plain test project creating a new Next.js project
- I've done a
- I then created a separate build folder with the following files (it's not clear in the layout but the other files aren't nested within
-
-
-
-
- After this I installed
- I then created a new application in IIS under
- I set the physical path to the build folder that contains the perviously named folders and files.
- I gave the correct user all of the necessary permissions on the application and the AppPool.
- I refreshed everything and "browsed" the application, which added the iisnode folder.
- I then got a (next.js)
After all of this I also tried adding
However, when I pointed the path to the
Surely I'm missing some crucial steps but I feel like I'm quite close to making this work. I'd love any kind of input or direction.
Any idea? I wouldn't mind getting in a call with someone.
Thank you in advance.
I've followed some guides on medium that explain the process, like this one: https://medium.com/@dipneupane/deploying-nextjs-application-on-windows-iis-server-cabdc22bccf8
The steps I've taken already to deploy the test project:
- I 've created a plain test project creating a new Next.js project
- I've done a
next build to create a build output.- I then created a separate build folder with the following files (it's not clear in the layout but the other files aren't nested within
.next:-
.next-
node_modules-
web.config (from the medium article)-
server.js (also from the medium article)- After this I installed
iisnode and URLRewrite as suggested in the guide.- I then created a new application in IIS under
Workstation > Sites > Default Web Site > iis-test-project- I set the physical path to the build folder that contains the perviously named folders and files.
- I gave the correct user all of the necessary permissions on the application and the AppPool.
- I refreshed everything and "browsed" the application, which added the iisnode folder.
- I then got a (next.js)
404 | Page not found.After all of this I also tried adding
output: "export" to the next.config.js. I repeated the same steps but then with out instead of .next. That also gave me a Build_ID error Error: ENOENT: no such file or directory, open 'C:\source\iis-test-project-build\.next\BUILD_ID'However, when I pointed the path to the
out file directly I did get to see the basic html but no css or anything.Surely I'm missing some crucial steps but I feel like I'm quite close to making this work. I'd love any kind of input or direction.
Any idea? I wouldn't mind getting in a call with someone.
Thank you in advance.
17 Replies
Managed to get a part working at least. Instead of an application underneath a Site, I made a new Site in IIS and directed the path to the build folder.
I now see a part of my application (an overlay) but the pages still give a 404. I managed to get the test application running this way though, with routing. So now I'll have to figure out why it's giving a 404 for the pages in my main application.
Toyger
maybe it'll be easier to run next as is with nodejs, and if IIS still requirement to run it through reverse proxy?
because I think even if you'll be able to run it normally for now, in future it will be big problem to maintain it.
because I think even if you'll be able to run it normally for now, in future it will be big problem to maintain it.
Would the application be able to interact with other IIS applications (under the same pool) if I host it with a reverse proxy?
@Toyger And just wondering, why would it be a big problem to maintain down the line?
@timvd7652 Would the application be able to interact with other IIS applications (under the same pool) if I host it with a reverse proxy?
Toyger
yeah they can interact, they still persist on same server so there are many ways to interconnect.
about maintaining, you see that even right now it is trouble to run it normally, for example there will be some critical updates, and they'll add some features that rely on new functionality of nodejs, or other framework, and
or some functions will be limited, or will generate some kind of "undefined behavior".
Even directly with node itself nextjs have enough issues open on github, but iisnode and windows can be another level of abstraction that can break compatibility.
about maintaining, you see that even right now it is trouble to run it normally, for example there will be some critical updates, and they'll add some features that rely on new functionality of nodejs, or other framework, and
iisnode will not keep up with updates quickly enough,or some functions will be limited, or will generate some kind of "undefined behavior".
Even directly with node itself nextjs have enough issues open on github, but iisnode and windows can be another level of abstraction that can break compatibility.
@Toyger yeah they can interact, they still persist on same server so there are many ways to interconnect.
about maintaining, you see that even right now it is trouble to run it normally, for example there will be some critical updates, and they'll add some features that rely on new functionality of nodejs, or other framework, and `iisnode` will not keep up with updates quickly enough,
or some functions will be limited, or will generate some kind of "undefined behavior".
Even directly with node itself nextjs have enough issues open on github, but iisnode and windows can be another level of abstraction that can break compatibility.
I see, so then I'd be looking at hosting it as a reverse proxy. It's something I've never done before but I read an article that mentioned pm2, do you have any experience with it or perhaps something else? Thank you for your reply by the way, I appreciate it, it's been quite a journey.
@timvd7652 I see, so then I'd be looking at hosting it as a reverse proxy. It's something I've never done before but I read an article that mentioned pm2, do you have any experience with it or perhaps something else? Thank you for your reply by the way, I appreciate it, it's been quite a journey.
Toyger
https://www.tevpro.com/blog/using-iis-as-a-reverse-proxy-server
you'll need something like that.
about pm2 yeah it's kinda usefull, and you more likely don't even need to configure it, by default it's kinda good.
So you run your nextjs on same machine with nodejs, with pm2 above it will be better because it will restart app on crash, and then it starts normally on
you'll need something like that.
about pm2 yeah it's kinda usefull, and you more likely don't even need to configure it, by default it's kinda good.
So you run your nextjs on same machine with nodejs, with pm2 above it will be better because it will restart app on crash, and then it starts normally on
http://localhost:3000 and you put this address in config from guide above and it should work much better. theoretically can be some problem with domain rewrite, but you'll just then can change domain in next config and write it into hosts file probably it should help.Perfect, I'm going to try that out, thank you so much!
Pechora Pipit
Hi Tim, how do you build the app? normally or using standlone mode?
@Pechora Pipit Hi, I'm building it normally. I've got (some parts) of it working now. One of the changes I've made is running it in IIS under a site instead aof an application that's under a site. The only difference I see is that it changes the route from localhost/NEXTJSAPP to localhost/9000. It's still not ideal because I will have to deploy it under an application eventually. Also, it's not finding the images from the public folder. Can't find them in the .next oflder either, which is odd.
I still have to try out the reverse proxy way after speaking. But any more information/help to run it like it is would still be much appreciated.
I still have to try out the reverse proxy way after speaking. But any more information/help to run it like it is would still be much appreciated.
Pechora Pipit
Yea, you have to copy the public files yourself to .next/standalone folder
I got it working today on localhost
so hopefully will on IIS later today as well
I managed to get it running on an IIS application (so an application running underneath a site). I've written a solution that will and should solve all of the routing problems. I still have to expirement a bit more but after I'm certain of everything I will will post my solution, which will hopefully help other developers struggling with this issue.
If I get more time from work to work on this, I'll look into the standalone output and the reverse proxy as well.