一.需要的插件
- iisnode 下載安裝(很重要) iisnode地址
//遇到不能下載的情況可以在網(wǎng)盤中提取
網(wǎng)盤:https://pan.baidu.com/s/1q1GlHa_e0W-kQNnVY7rLaQ
提取碼:hwf4
- 下載url重寫 在iis的web平臺安裝程序中搜索并安裝
二.把入口文件 改成index.js
1.項目根目錄新建index.js 復制bin/www內(nèi)的內(nèi)容到index.js *注意index.js引入的文件路徑*
// 2.并在package.json 中修改
"scripts": {
"dev": "node-dev index.js"
},
三.設置web.config
<configuration>
<system.webServer>
<!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module -->
<handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" resourceType="Unspecified" requireAccess="Script" preCondition="bitness64" />
</handlers>
<rewrite>
<rules>
<rule name="all">
<match url="/*" />
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite>
<iisnode
node_env="%node_env%"
nodeProcessCountPerApplication="1"
maxConcurrentRequestsPerProcess="1024"
maxNamedPipeConnectionRetry="100"
namedPipeConnectionRetryDelay="250"
maxNamedPipeConnectionPoolSize="512"
maxNamedPipePooledConnectionAge="30000"
asyncCompletionThreadCount="0"
initialRequestBufferSize="4096"
maxRequestBufferSize="65536"
watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade"
uncFileChangesPollingInterval="5000"
gracefulShutdownTimeout="60000"
loggingEnabled="true"
logDirectory="iisnode"
debuggingEnabled="true"
debugHeaderEnabled="false"
debuggerPortRange="5058-6058"
debuggerPathSegment="debug"
maxLogFileSizeInKB="128"
maxTotalLogFileSizeInKB="1024"
maxLogFiles="20"
devErrorsEnabled="true"
flushResponse="false"
enableXFF="false"
configOverrides="iisnode.yml"
nodeProcessCommandLine="C:\Program Files\nodejs\node.exe"
promoteServerVars="REMOTE_ADDR" />
<defaultDocument>
<files>
<add value="index.js" />
</files>
</defaultDocument>
</system.webServer>
</configuration>
四.如果遇到下面的問題
iisnode encountered an error when processing the reques.
HRESULT: 0x2 HTTP.
status: 500
You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'.
...
//解決方法
1.找到項目的根目錄 右擊鼠標 進入屬性頁面
2.點擊 *安全* 按鈕抓歼,點擊編輯按鈕
3.點擊添加按鈕,添加一個自定義組或用戶名
4.選擇自定義的組或用戶名,選擇所有權(quán)限點擊確定
權(quán)限設置.png
五.新建網(wǎng)站
具體內(nèi)容移步: 詳細過程
六.通過花生殼內(nèi)網(wǎng)傳透绵估,設置外網(wǎng)訪問
*(1)設置防火墻的入棧規(guī)則
-
1.首先打開控制面板中的防火墻爆捞,點擊高級設置
高級設置.png - 2.進入高級設置后奉瘤,點擊入棧規(guī)則,在操作一欄點擊新建規(guī)則
入棧規(guī)則.png
- 3.在規(guī)則類型中選擇 端口
規(guī)則類型.png -
4 協(xié)議和端口分別選擇 TCP和 設置的端口號
協(xié)議和端口.png - 5 操作及配置文件 :默認或者自定義
- 6 名稱: 建議設置成和項目有關(guān)的,方便查找和刪除
(2)花生殼內(nèi)網(wǎng)映射
-
1.類型選擇http煮甥,外網(wǎng)域名自帶兩個(可創(chuàng)建一個)盗温,外網(wǎng)端口隨機,內(nèi)網(wǎng)本機ip地址成肘,端口自定義的端口
內(nèi)網(wǎng)映射.png -
2.訪問外網(wǎng)接口
訪問.png