#Deploying Next.js on IIS

18 messages · Page 1 of 1 (latest)

obsidian dew
#

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 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.

Medium

NextJs is the server-side rendered React-based framework for creating Single page applications. It is most popular because of its…

lyric starBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

obsidian dew
#

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.

copper sorrel
#

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.

obsidian dew
#

Would the application be able to interact with other IIS applications (under the same pool) if I host it with a reverse proxy?

#

@copper sorrel And just wondering, why would it be a big problem to maintain down the line?

copper sorrel
# obsidian dew Would the application be able to interact with other IIS applications (under the...

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.

obsidian dew
copper sorrel
# obsidian dew I see, so then I'd be looking at hosting it as a reverse proxy. It's something I...

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 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.

obsidian dew
#

Perfect, I'm going to try that out, thank you so much!

chrome copper
#

Hi Tim, how do you build the app? normally or using standlone mode?

obsidian dew
#

@chrome copper 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.

chrome copper
#

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

obsidian dew
#

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.