Mean Stack 安装在端口 80 或 iis 下

Mean Stack install on port 80 or or under iis

我有一个 Mean stack 应用程序,现在可以在 Node Js 和端口 3000 上运行。 我有一个 Windows Server 2016,我需要部署 .Net 应用程序,所以我需要 IIS。 我无法在端口 80 上同时创建 运行 两个 Web 服务器,但我不希望用户被迫键入 运行 宁我的 Mean 应用程序所在的端口。 我尝试使用 iisnode,但没有成功,我还阅读了有关反向代理的信息,以便将端口 80 上的请求重定向到另一个端口。 这两种解决方案都可能有效,但是,在将其他时间花在错误的方向上之前,我想问一下在这种情况下最佳做法是什么。

更新: 向前迈出一小步。 我现在可以访问应用程序的加载页面,但是应用程序找不到我的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>

我努力调整配置和路径,但没有结果...

谢谢

最大

用于 IIS 的带 ARR 模块的反向代理将是实现您想要的目标的最佳方式。

  1. 您需要为 IIS
  2. 安装 URL Rewrite and ARR module
  3. 启用 ARR。在 Application Request Routing 页面上,select Enable proxy
  4. 在 IIS 管理器中创建网站
  5. 在此网站文件夹中创建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 会将您的请求代理到端口 3000