[英]How to run a node.js app in an azure website subdirectory
我已經使用Azure創建了一個網站,我想在子目錄(例如app1 / test)中運行node.js應用程序,而不是創建一個新網站並在根目錄中運行該應用程序。
這是我的目錄的結構
-wwwroot / web.config中
-wwwroot / index.html的
-wwwroot / APP1 /測試/的package.json
-wwwroot / APP1 /測試/ server.js
所以在root中有一個index.html,然后我在test子目錄中有了server.js。
這是我的server.js:
var http = require('http');
var port = process.env.port || 1337;
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
這是我的package.json:
{
"name": "test",
"version": "0.0.0",
"description": "test",
"main": "server.js",
"author": {
"name": "name",
"email": ""
},
"dependencies": {
}
}
我的web.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<location path="app1/test">
<system.webServer>
<modules runAllManagedModulesForAllRequests="false" />
<!-- indicates that the server.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="app" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
<match url="iisnode.+" negate="true" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Rewrite" url="server.js" />
</rule>
</rules>
</rewrite>
</system.webServer>
</location>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
</system.webServer>
</configuration>
但我明白了
“由於發生內部服務器錯誤,無法顯示頁面。”
當我點擊域名/ app1 /測試
不確定我的web.config有什么問題,如果我需要手動安裝iisnode。
我感謝任何幫助。
謝謝
我解決了! 以下作品!
<match url="app1/test" />
<action type="Rewrite" url="app1/test/server.js" />
您需要檢查您的請求網址是否位於您正在檢查的位置,在這種情況下:
var http = require('http');
var port = process.env.port || 1337;
http.createServer(function (req, res) {
if(req.url === '/app1/test')
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(port);
然后你可以通過轉到頁面進行測試
http://localhost:1337/app1/test
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.