nuxt.js不能通过域名或其他ip访问,是什么原因?

我的nuxt服务运行在Nuxt ready on http://127.0.0.1:3000/,那么通过http://localhost:3000/或者局域网ip http://192.168.1.105:3000/都不能访问,只有http://127.0.0.1:3000/能够正常访问,是什么原因?怎么解决?

使用的是nuxt的项目模板,package如下:

{
    "name": "nuxt",
    "version": "1.0.0",
    "description": "Nuxt.js project",
    "author": "jawei <1005945485@qq.com>",
    "private": true,
    "dependencies": {
        "leancloud-storage": "^3.0.1",
        "muse-ui": "^2.0.3",
        "nuxt": "latest"
    },
    "config": {
        "nuxt": {
            "host": "127.0.0.1",
            "port": "3000"
        }
    },
    "scripts": {
        "dev": "nuxt",
        "build": "nuxt build",
        "start": "nuxt start",
        "generate": "nuxt generate",
        "lint": "eslint --ext .js,.vue --ignore-path .gitignore .",
        "precommit": "npm run lint"
    },
    "devDependencies": {
        "babel-eslint": "^7.1.1",
        "eslint": "^3.15.0",
        "eslint-config-standard": "^6.2.1",
        "eslint-loader": "^1.6.1",
        "eslint-plugin-html": "^2.0.0",
        "eslint-plugin-promise": "^3.4.1",
        "eslint-plugin-standard": "^2.0.1"
    }
}

回答:

“config”: {

    "nuxt": {
        "host": "0.0.0.0",
        "port": "3000"
    }
},

回答:

应该是因为你配置了 host

"config": {
    "nuxt": {
        "host": "127.0.0.1"           

回答:

在server/index.js 中把host改为

const host = process.env.HOST || '0.0.0.0'

原因: 在服务器中,0.0.0.0指的是本机上的所有IPV4地址 127.0.0.1 和 localhost都不行

暂无评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注