nuxtjs项目在服务器上使用pm2运行后无法访问

391 阅读1分钟

nuxtjs项目在本地运行正常,打包到服务器上后使用pm2运行起来,一切看似正常,(防火墙已经开启可用端口),但是在却无法访问(用npm run start 就能访问),需要修改两个文件pacjage.json 和 nuxt.config.js

nuxt.config.js 和head同级

server: {
    port: 3000, // 这个端口自己定
    host: '0.0.0.0',
},

package.json 添加

"config": {
    "nuxt": {
      "host": "0.0.0.0",
      "post": 3000  // 这个端口自己定
    }
  }

配置完之后再用pm2 启动项目,就可以正常访问了

我使用的命令是

pm2 start ./node_modules/nuxt/bin/nuxt.js --name "nuxt1" --watch -- start