2017-05-07 72 views
1

我有現在的作品在節點的js我有一個Windows Server 2016年平均棧的應用程序和端口3000 ,我需要部署.NET應用程序,所以我需要IIS。 我無法在端口80上運行兩個Web服務器,但我不希望用戶被迫鍵入運行我的Mean應用程序的端口。 我試着用iisnode工作,但沒有成功,我以80端口的請求重定向到另一個端口也讀到反向代理。 這兩種解決方案都可能是有效的,但是,在將其他時間花在錯誤的方向上之前,我會問在這種情況下最佳做法是什麼。平均堆棧上安裝端口80或或IIS下

UPDATE: 向前邁進了一小步。 我現在可以訪問應用程序的加載頁面,但應用程序無法找到我的bundle.js(由創建的WebPack包)。

module.exports = webpackMerge.smart(commonConfig, { 
    entry: { 
     'app': './assets/app/main.aot.ts' 
    }, 

    output: { 
     path: path.resolve(__dirname + '/public/js/app'), 
     filename: 'bundle.js', 
     publicPath: '/js/app/', 
     chunkFilename: '[id].[hash].chunk.js' 
    }, 

我的web.config是:

<configuration> 
    <system.webServer> 
    <handlers> 
     <add name="iisnode" path="start.js" verb="*" modules="iisnode" /> 
    </handlers> 
    <rewrite> 
     <rules> 
     <rule name="tep"> 
      <match url="/*" /> 
      <action type="Rewrite" url="start.js" /> 
     </rule> 
     </rules> 
    </rewrite> 
    <security> 
     <requestFiltering> 
     <hiddenSegments> 
      <add segment="node_modules" /> 
     </hiddenSegments> 
     </requestFiltering> 
    </security> 
    </system.webServer> 
</configuration> 

start.js文件的摘錄:

var app = require('./app'); 
var debug = require('debug')('node-rest:server'); 
var http = require('http'); 

var port = normalizePort(process.env.PORT || '3000'); 
app.set('port', port); 

var server = http.createServer(app); 

server.listen(port); 
server.on('error', onError); 
server.on('listening', onListening); 

和視圖(HBS):

<!DOCTYPE html> 
<html> 
<head> 
    <base href="/tep"> 
    <title>Tennis Events Pro</title> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> 

</head> 
<body> 
<tep-app>Loading...</tep-app> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
<script src="/tep/bundle.js"></script> 
</body> 
</html> 

我圍繞調整配置和路徑,沒有結果......

感謝

最大

+1

我建議使用nginx的作爲轉發代理。更多的相關信息在這裏: - https://ef.gy/using-nginx-as-a-proxy-server,-https://gist.github.com/soheilhy/8b94347ff8336d971ad0 –

+0

看看這個約iisnode:HTTPS ://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx – wannadream

回答

1

與IIS ARR模塊反向代理服務器將最好的方式來實現你想要的。

  1. 您需要安裝URL RewriteARR module爲IIS
  2. 啓用ARR。在Application Request Routing頁面上,選擇Enable proxy
  3. 在IIS管理器中創建網站
  4. 本網站文件夾中創建的web.config

    <?xml version="1.0" encoding="UTF-8"?><configuration>

    <system.webServer> 
        <rewrite> 
         <rules> 
          <rule name="rewrite to 3000" stopProcessing="true"> 
           <match url="(.*)" /> 
           <action type="Rewrite" url="http://127.0.0.1:3000/{R:1}" /> 
          </rule> 
         </rules> 
        </rewrite> 
    </system.webServer> 
    

    </configuration>

之後,步驟IIS會將您的請求代理給p ORT 3000