Last active
July 10, 2025 08:26
-
-
Save valakhosravi/a861b00f36dda6b0f0185a53631cc22d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Deploying a Next.js project to a Windows Server running IIS involves several steps. Here are the high-level steps you can follow: | |
Build your Next.js project using the following command: | |
npm run build | |
This will create a production build of your project in the ./out directory. | |
Create a new website in IIS and configure it to use the ./out directory as the physical path. | |
Set up the Node.js IIS HTTP Module on your server if it's not already installed. You can download and install it from the official Microsoft website. | |
Configure the Node.js IIS HTTP Module to use the Node.js runtime on your server. You can do this by creating a new web.config file in the ./out directory and adding the following configuration: | |
<configuration> | |
<system.webServer> | |
<handlers> | |
<add name="iisnode" path="server.js" verb="*" modules="iisnode" /> | |
</handlers> | |
<rewrite> | |
<rules> | |
<rule name="Next.js" enabled="true" stopProcessing="true"> | |
<match url="^(.*)$" /> | |
<conditions logicalGrouping="MatchAll"> | |
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> | |
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> | |
</conditions> | |
<action type="Rewrite" url="server.js" /> | |
</rule> | |
</rules> | |
</rewrite> | |
<iisnode node_env="%node_env%" nodeProcessCountPerApplication="1" /> | |
</system.webServer> | |
</configuration> | |
This configuration tells IIS to use the iisnode module to run the server.js file in your project's ./out directory. It also sets the node_env environment variable to the value of the NODE_ENV environment variable on your server. | |
Restart IIS to ensure that the changes take effect. | |
Navigate to the URL of your website in a web browser to confirm that your Next.js application is running correctly. | |
That's it! You should now have a working Next.js application deployed to your Windows Server running IIS. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment