Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js 如何使用IIS部署Nuxt_Vue.js_Iis_Nuxt.js_Iisnode - Fatal编程技术网

Vue.js 如何使用IIS部署Nuxt

Vue.js 如何使用IIS部署Nuxt,vue.js,iis,nuxt.js,iisnode,Vue.js,Iis,Nuxt.js,Iisnode,我想在IIS中部署Nuxt我正在使用IIS节点,但无法使其工作。。。 我可以在我的服务器上使用npm run start,但是我有其他项目,比如admin y api(.net),它使用端口80,所以当我使用端口80时,它很忙,而在IIS中它使用这种结构 这是我在web.config中的代码 <?xml version="1.0" encoding="utf-8"?> <!-- This configuration file is required if iisn

我想在IIS中部署Nuxt我正在使用IIS节点,但无法使其工作。。。

我可以在我的服务器上使用npm run start,但是我有其他项目,比如admin y api(.net),它使用端口80,所以当我使用端口80时,它很忙,而在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与express结合使用之前,请忽略nuxt.config.js,但它不起作用,因为我使用的是ES6,当它尝试运行nuxt.config时,在语法方面出错了(请确保安装了节点)

2) 使用以下命令创建nutx应用程序:

npm init nuxt-app testnu

3) 进入应用程序文件夹并运行以下命令以构建站点:

npm run generate
此命令将在应用程序文件夹中生成dist文件夹

4) 在IIS中创建站点,并将dist文件夹路径指向站点路径,并分配站点绑定信息

5) 不要忘记将iis_iusr和iusr权限分配给站点文件夹。(我的情况是站点文件夹为testnu)

6) 进行更改后刷新并重新启动站点并浏览站点


问题是您必须使用server.js文件来运行node.js服务器。 语法错误可能是在config.js中导出时出现的,可以通过将
export default{…
更改为
module.exports={…

您的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();
  "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"
  }
该文件与
numxt.config.js
处于同一级别(当您选择express作为自定义服务器框架时,请将其随意移动到
server/index.js
,就像
numxt-create-app
一样,并将配置导入更改为
const-config=require('../numxt.config.js');

不要忘记在
web.config
中更改重写规则和iisnode模块到server.js文件的路径

如果要在生产模式下运行,还需要将
添加到
web.config

还考虑为每个环境添加一个单独的配置文件,然后在<代码>包中。JSON < /代码>您可以这样切换:

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();
  "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-dev
warn-build-dev
这样构建。嗨,谢谢。你知道npm-run-build的方法吗?我有一个ssr,我使用动态路由,所以刷新时出现404错误…你可以尝试运行npm-run-build命令来构建应用程序,但我不确定该命令。你可以使用hel但在我看来,对于ssr,您可以使用这个命令npm run generate。