如何使用IIS部署Nuxt

jjhzyzn0  于 2022-11-12  发布在  其他
关注(0)|答案(4)|浏览(357)

我 想 在 IIS 中 部署 Nuxt 我 正在 使用 IIS 节点 , 但 无法 使 其 正常 工作 ... Folder
我 可以 在 我 的 服务 器 中 使用 npm run start 来 执行 此 操作 , 但 我 有 其他 项目 , 如 admin y api ( . net ) , 它 使用 的 是 端口 80 , 因此 当 我 使用 端口 80 时 , 它 处于 繁忙 状态 , 而 在 IIS 中 , 它 使用 Folder IIS 结构
这 是 我 在 web.config 中 代码

<?xml version="1.0" encoding="utf-8"?>
<!--
     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>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <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="nuxt.config.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="^nuxt.config.js\/debug[\/]?" />
        </rule>

        <!-- <rule name="Redirect to https" stopProcessing="true">
          <match url="(.*)"/>
          <conditions>
            <add input="{HTTPS}" pattern="Off"/>
            <add input="{REQUEST_METHOD}" pattern="^get$|^head$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
        </rule> -->

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </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="nuxt.config.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:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>

中 的 每 一 个
在 使用 server.js 之前 , 我 忽略 了 nuxt.config.js , 但 它 不 起 作用 , 因为 我 使用 的 是 ES6 , 当 它 尝试 运行 nuxt.config 时 , 出现 了 语法 错误

jdgnovmf

jdgnovmf1#

1)请确保安装了该节点。
https://nodejs.org/en/download/
2)使用以下命令创建nutx应用程序:

npm init nuxt-app testnu

3)进入app文件夹并运行以下命令来构建站点:

npm run generate

此命令将在您的应用程序文件夹中生成dist文件夹。
4)在IIS中创建一个站点,并将dist文件夹路径作为站点路径指向,然后分配站点绑定信息。

5)不要忘记为站点文件夹分配iis_iusrs和iusr权限。(在我的情况下,站点文件夹是testnu)

6)请在进行更改后刷新并重新启动站点,然后浏览站点。

jhkqcmku

jhkqcmku2#

问题是,您必须使用server.js文件来运行node.js服务器。
您的server.js文件应如下所示:

const express = require('express');
const consola = require('consola');
const { Nuxt, Builder } = require('nuxt');
const app = express();

const config = require('./nuxt.config.js');
config.dev = process.env.NODE_ENV !== 'production';

async function start() {
  const nuxt = new Nuxt(config);
  const { host, port } = nuxt.options.server;

  if (config.dev) {
    const builder = new Builder(nuxt);
    await builder.build();
  } else {
    await nuxt.ready();
  }

  app.use(nuxt.render);

  app.listen(port, host);
  consola.ready({
    message: `Server listening on http://${host}:${port}`,
    badge: true
  });
}

start();

该文件与nuxt.config.js处于同一级别(当您选择express作为自定义服务器框架并将config import更改为const config = require('../nuxt.config.js');时,您可以像nuxt-create-app一样将其移动到server/index.js)。
另外,不要忘记将重写规则和iisnode模块的路径更改为web.config中的server.js文件。
如果要在生产模式下运行,还需要将<iisnode node_env="development" />添加到web.config中。
还可以考虑为每个环境添加一个单独的配置文件,然后在package.json中可以这样切换它们:

"scripts": {
    "dev": "nuxt",
    "build-local": "nuxt build",
    "build-dev": "nuxt build --config-file nuxt.config.dev.js",
    "build": "nuxt build --config-file nuxt.config.prod.js",
    "start": "nuxt start",
    "generate": "nuxt generate"
  }

然后构建npm run build-devyarn build-dev

zujrkrfu

zujrkrfu3#

任何试图使用IIS托管任何类型的Javascript SPA或节点应用程序的人都应该知道URL重写。就像下面的例子一样。我已经用静态React、Angular 、nextjs SPA尝试过了。
https://gist.github.com/maxan/0d124ed677ebe41e1aeaf4a9e1e6aa45

8ehkhllq

8ehkhllq4#

说明:

1.添加或安装IIS
1.a)打开**“打开或关闭Windows功能”,然后找到“Internet信息服务”**
2.b)从**“Internet信息服务”“万维网服务”检查除“CGI”以外的所有项目
3.c)单击“确定”按钮并重新启动系统
2.安装
IISNode**(如果您的系统中不存在,请下载并安装)
3.安装Url Rewrite(如果您的系统中不存在,请下载并安装)
4.将nuxt.config.js文件的第一行从export default {更改为module.exports = {
5.在项目中运行命令npm install nuxt-start
6.安装express =〉npm install express
7.将Server文件夹和web.config文件复制到项目路径的根目录
8.构建您的nuxt应用程序=〉npm run build

IIS说明:

1.添加网站
2.设置名称将物理路径更改为项目的根目录
3.输入自定义端口,如“3000”,然后单击“OK”按钮
3.点击应用程序池(在IIS窗口的左窗格中,在“站点”旁边),然后右键点击“您的网站池”,然后右键点击它并选择高级设置
4.将身份更改为“LocalSystem”,然后单击“确定”按钮

**注意:**如果遇到任何错误,请打开项目根目录中的iisnode文件夹以检查日志。

相关问题