Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9311

Windows ServerのIISにNode-REDをデプロイ

$
0
0
初めに Windows server 2008 iisnodeを用いて簡単にIIS上にNodeアプリをデプロイする 今回はNode-REDをインストールする 手段 Windows Server バックアップ上でバックアップを作成 NodeからLTS版をダウンロードしてをインストールする Azure/iisnodeのページからビルドをダウンロードしてインストールする 再起動する C:\Program Files\iisnodeのsetupsamples.batを実行。注意事項が出るので十分に読んで続行すること カスタムユーザーグループがある場合はIIS上でそのグループにアクセス権限を付与する node-REDインストール C:\Program Files\iisnode\www\にxredディレクトリを作成し、そこに移動する。 ファイル(server.js, settings.js, web.config)、ディレクトリ(node-red)を作成 C:\Program Files\iisnode\www\xred上でpowershellを起動。以下のコマンドを実行 node-redは--globalでインストールしない。これは、別のExpressアプリでラップするため、globalである必要がないためである。(globalの場合はリバースプロキシを使う必要があり、httpだけでなくwebsocketも対応する必要がある。私の能力ではwebsocketの対応はできず、動かなかった。) npm install --global --production windows-build-tools npm install node-red server.jsの内容 var express = require("express"); var RED=require('node-red'); var app= express(); var http=require('http'); const PORT=process.env.PORT; //||8000; var server=http.createServer(app); var settings=require("./settings.js"); RED.init(server,settings); app.use(settings.httpAdminRoot,RED.httpAdmin); app.use(settings.httpNodeRoot,RED.httpNode); server.listen(settings.uiPort); console.log(`listening port:${settings.uiPort}`); RED.start(); settings.jsの内容 module.exports = { httpAdminRoot:"/node/xred/", httpNodeRoot: "/node/xred/", userDir:"./node-red/", uiPort: process.env.PORT, // || 8000 } web.configの内容 <!-- This configuration file is required if iisnode is used to run node processes behind IIS or IIS Express. For more information, visit: https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config --> <configuration> <system.webServer> <webSocket enabled="false" /> <handlers> <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module --> <add name="iisnode" path="server.js" verb="*" modules="iisnode" /> <!--<add name="iisnode" path="hello.js" verb="*" modules="iisnode"/>--> </handlers> <rewrite> <rules> <!-- Do not interfere with requests for node-inspector debugging--> <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true"> <match url="server.js\/debug[\/]?" /> </rule> <!-- First we consider whether the incoming URL matches a physical file in the /public folder --> <rule name="StaticContent"> <action type="Rewrite" url="public{PATH_INFO}" /> </rule> <!-- All other URLs are mapped to the node.js site entry point--> <rule name="DynamicContent"> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" /> </conditions> <action type="Rewrite" url="server.js" /> </rule> </rules> </rewrite> <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it --> <security> <requestFiltering> <hiddenSegments> <remove segment="bin" /> </hiddenSegments> </requestFiltering> </security> <!-- Make sure error responses are left untouched --> <httpErrors existingResponse="PassThrough" /> <!-- You can control how Node is hosted within IIS using the following options: See iisnode on github for a full list of options --> <iisnode watchedFiles="web.config;*.js" loggingEnabled="true" logDirectory="iisnode" debuggingEnabled="true" /> </system.webServer> </configuration> 再起動時のNode-RED自動起動設定 タスクスケジューラーでnode-modules/node-red/red.jsを起動時に実行するように設定する。 コメント cannot GETと出た場合はsettings.jsのパスが間違っている可能性が高い 初めてアクセスした場合にNot startedと出る。これは正常であり、しばらくしてからアクセスすれば正常に動く 403エラーが出る場合はIISでエラーページの詳細設定から詳細なログを表示に設定し、原因を特定する 自分の場合はnode/index.phpを探していて、ファイルがないと怒られた IISの既定のドキュメントでindex.htmを一番上に移動するとnode/index.htmを探すようになる 参考リンク https://qiita.com/joeartsea/items/93e8483a31292067c654 https://nodered.org/docs/getting-started/windows#running-on-windows https://discourse.nodered.org/t/installing-on-win-2012-server-r2/4585/3

Viewing all articles
Browse latest Browse all 9311

Trending Articles