# Next.js hosting configurations

## Overview

This article contains Next.js and Sitefinity CMS configurations based on where your Sitefinity CMS project is hosted.

## Sitefinity CMS hosted in Sitefinity Cloud

Additional project setup steps for Sitefinity CMS application hosted in Sitefinity Cloud:

1. In Sitefinity Cloud, navigate to your dedicated Key Vault instance.\
   For more information, see [Azure Key Vault](https://www.progress.com/documentation/sitefinity-cms/cloud/develop-and-deploy/azure-key-vault). Under *Secrets*, find the `LocalValidationKey` and copy the value of the secret.
2. Set the `SF_LOCAL_VALIDATION_KEY` environment variable with the value of the secret copied in the previous step.\
   For more information, see [Set up the project for local development (using Next.js Renderer)](https://www.progress.com/documentation/sitefinity-cms/cloud/develop-and-deploy/set-up-the-project-for-local-development--using-next.js-renderer-).

## Sitefinity CMS hosted in Azure

If your project is hosted on Azure App Services, you need to make some specific settings, so that your Sitefinity CMS can communicate with the Renderer application:

1. Set up a 64-bit process in the App Service platform configuration. To do this, perform the following:
   1. In the Azure portal, click *Your service*.
   2. Under *Settings*, click *Configuration*.
   3. Click *General settings*.
   4. In *Platform* dropdown box, select *64 Bit*.
   5. Restart the app service.
2. Rewrite the `X-Original-Host` header sent from the Renderer to Host header. To do this, install an additional extension from the Kudu console in the following way:
   1. In the Azure Portal, click *Your service*.
   2. In the sidebar, under *Development tools* section, click *Advanced Tools » Go*.
   3. In the *Kudu* console, expand the *Site extensions*.
   4. Search for the *Application Gateway Host Rewrite Module* and follow the installation instructions.
   5. Restart the Kudu service.

## Sitefinity CMS hosted on IIS

If your project is hosted on a local IIS, you need to make some specific settings, so that your Sitefinity CMS can communicate with the Renderer application:

1. Download the NuGet package `Progress.Sitefinity.Cloud.AppGatewayHostRewriteModule`.
2. Change the file extension from `.nupkg` to `.zip` and extract the files.
3. In the extracted folder, navigate to the *Content* folder.
4. Copy the `HostRewriteModule.dll` and paste in a dedicated folder.

> info  **NOTE**: IIS's NETWORK SERVICE must have permissions to access the folder. The file must remain in this folder for as long as the extension is used. Deleting the file or its folder can cause issues.

1. Open Internet Information Services (IIS) Manager.
2. At the top, select your server and click *Modules*.
3. Click *Configure Native Modules » Register*.
4. Set the name to `AppGatewayHostRewriteModule.`
5. In *Path*, navigate to the *HostRewriteModule.dll*, select it and click *OK*.
6. Ensure the checkbox next to *AppGatewayHostRewriteModule* is selected and click *OK*.

## Next.js Renderer hosted on IIS (using HttpPlatformHandler)

If you wish to host your Next.JS Renderer under IIS, you need to set up IIS to act as a proxy to your original application:

1. Install `HttpPlatformHandler` v1.2.
2. Add the following `web.config` file in the root of the web app:
   ```XML
   <?xml version="1.0" encoding="UTF-8"?>
   <configuration>
       <system.webServer>
           <handlers>
               <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
           </handlers>
           <httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\node.log" startupTimeLimit="20" processPath="C:\Program Files\nodejs\node.exe" arguments=".\node_modules\next\dist\bin\next dev">
               <environmentVariables>
                   <environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
                   <environmentVariable name="SF_PROXY_ORIGINAL_HOST" value="localhost:8081" />
                   <environmentVariable name="NODE_ENV" value="Development" />
               </environmentVariables>
           </httpPlatform>
       </system.webServer>
   </configuration>
   ```
3. Be sure to replace the paths to node.exe and next if they are different.
4. Set the `SF_PROXY_ORIGINAL_HOST` to the actual domain of the Next.js Renderer app that will be used for hosting in IIS.

## Next.js Renderer hosted on docker

When the renderer is hosted on docker the resolved host from the http request is in the form of 'localhost' or 'localhost:port'. Make sure to pass to the `X-ORIGINAL-HOST` header, the proper value with the actual domain.

If using a single site only, you can pass the value through the `SF_PROXY_ORIGINAL_HOST` environment variable.
