Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add iis preset #1035

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions docs/content/2.deploy/1.node.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,110 @@ import handler from './.output/server'
const server = createServer(handler)
server.listen(8080)
```

## IIS

You can either use [IISnode](https://github.com/Azure/iisnode) (recommended for Nuxt) or IIS directly.
Make sure that [node.js](https://nodejs.org/en/) is installed on your Windows Server.

### Using IISnode

IISnode supports SSR build, but requires configuration required

Install [IISnode x64](https://github.com/azure/iisnode/releases/download/v0.2.21/iisnode-full-v0.2.21-x64.msi) or [IISnode x86](https://github.com/azure/iisnode/releases/download/v0.2.21/iisnode-full-v0.2.21-x86.msi), and the [IIS URL Rewrite Module](https://www.iis.net/downloads/microsoft/url-rewrite).

Run `npm run build` to generate the `.output` folder and add a `web.config` file into the `.output` folder

```xml
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<webSocket enabled="false" />
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server\/debug[\/]?" />
</rule>

<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>

<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="index.js"/>
</rule>
</rules>
</rewrite>

<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
<add segment="node_modules"/>
</hiddenSegments>
</requestFiltering>
</security>

<httpErrors existingResponse="PassThrough" />

<iisnode watchedFiles="web.config;*.js" node_env="production" debuggingEnabled="true" />
</system.webServer>
</configuration>
```

Add an `index.js` file into the root of the `.output` folder with the following content:

```js
import('./server/index.mjs');
```

Deploy the contents of your `.output` folder to your website in IIS.

```bash
+-- server
| +-- chunks
| +-- node_modules
| +-- index.mjs
| +-- index.mjs.map
| +-- package.json
+-- public
| +-- _nuxt
+-- index.js
+-- nitro.json
+-- web.config
```

In IIS, add `.mjs` as a new mime type and set its content type to `application/javascript`.

### Using IIS

If you do not wish to use IISnode, you can use IIS directly.
Install the `HttpPlatformHandler` IIS Module. This module manages HTTP Listeners and acts as a proxy.
Add a `web.config` to the `.output` directory after the build. It should look like this:

```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=".\logs\node.log" startupTimeLimit="20" processPath="C:\Program Files\nodejs\node.exe" arguments=".\server\index.mjs">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="NODE_ENV" value="Production" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
```

Additional `environmentVariables` can be added accordingly.

Finally, copy your `.output` directory into the Windows Server, and create a website on IIS pointing to that exact directory.