簡體   English   中英

node.js https server.listen拋出getaddrinfo ENOTFOUND example.com

[英]node.js https server.listen throws getaddrinfo ENOTFOUND example.com

我有一個在Debian 7服務器上運行的Express javascript服務器。 我大約在8到10天前進行了設置,效果很好。 我可以請求所有可用的路徑並獲得正確的響應。

今天,我意識到由於某種原因,請求https://example.com:1234/examplepath不再有效。 我登錄到服務器,發現快遞服務器仍在運行,但沒有任何請求通過。 因此,我停止了服務器並嘗試再次啟動它。 但是8到10天前起作用的東西現在突然拋出錯誤

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的相關代碼。

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(port,'localhost',()工作正常。

我沒有更改代碼或服務器上的任何內容。

好吧,原來我的域名提供商搞砸了。 一切再次正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM