首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >node.js https server.listen抛出getaddrinfo ENOTFOUND example.com

node.js https server.listen抛出getaddrinfo ENOTFOUND example.com
EN

Stack Overflow用户
提问于 2018-09-24 17:45:50
回答 1查看 371关注 0票数 0

我在Debian 7服务器上运行了一个快捷javascript服务器。我在8-10天前就安排好了,一切都很顺利。我可以请求所有可用的路径并得到正确的响应。

今天,我意识到,由于某种原因,请求https://example.com:1234/examplepath不再有效。我登录到我的服务器,看到快递服务器仍在运行,但没有请求通过。因此,我停止了服务器,并试图再次启动它。但是8-10天前起作用的现在突然抛出了错误。

代码语言:javascript
运行
复制
events.js:160
  throw er; // Unhandled 'error' event
  ^

Error: getaddrinfo ENOTFOUND example.com
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

这里是我的server.js.的相关代码

代码语言:javascript
运行
复制
const app = express();
const helmet = require('helmet');
app.use(helmet());
app.use(helmet.contentSecurityPolicy({
    directives: {
        defaultSrc:["'self'"]
    }
}));
app.use(helmet.expectCt());
app.use(helmet.noCache());
app.use(helmet.referrerPolicy());

const port = 1234;
const hostname = 'example.com';

const options = {
    key: fs.readFileSync('/etc/letsencrypt/live/example.com/privkey.pem'),
    cert: fs.readFileSync('/etc/letsencrypt/live/example.com/fullchain.pem')
};

...

MongoClient.connect(db.url, (error, database) => {
    if (error) return console.log(error);

    require('./app/routes')(app, database.db("placeholder"), config);

    https.createServer(options, app).listen(port, hostname, () => {
        console.log('We are live on ' + hostname + ':' + port);
    });
});

使用https.createServer创建服务器是可行的,但是调用listen()会抛出上面提到的错误。证书是最新的,执行.listen(端口、'localhost‘、()可以正常工作。

我没有在代码或服务器上更改任何内容。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-14 07:13:47

原来我的域名提供商搞砸了。一切都恢复正常了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52484722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档