我正在尝试在Windows Server 2012上使用两台Node.js Express服务器,每台服务器具有不同的FQDN(example1.b.br | exemple2.b.br)。 这些应用程序是两个Watson Chatbot,因此它们都需要使用route / conversation与IBM进行通信。
一个聊天机器人使用端口443,另一个使用8443。
问题是:它们中的每一个都位于不同的目录中,并且有自己的子目录“ public”,但是当我执行两个服务器时,使用端口8443的服务器使用端口443服务器的“ public”子目录。
聊天机器人
Chatbot1
node_modules
公共
Chatbot1 app.js:
const AssistantV1 = require('watson-developer-cloud/assistant/v1');
const express = require('express');
const bodyParser = require('body-parser');
const http = require('http');
const https = require('https');
var fs = require('fs');
var httpApp = express();
var workspace;
var options = {
key: fs.readFileSync('certificates/key.pem'),
cert: fs.readFileSync('certificates/server.crt')
};
const app = express();
app.use(bodyParser.json());
app.use(express.static('./public'));
const port = 80;
const httpsPort = 8443;
httpApp.set('port', process.env.PORT || 80);
const assistant = new AssistantV1({
username: 'XXXXX',
password: 'XXXXX',
url: 'https://gateway.watsonplatform.net/assistant/api/',
version: '2018-02-16'
});
workspace = 'XXXXXXX';
app.post('/conversation/', (req, res) => {
const { text, context = {} } = req.body;
const params = {
input: { text },
workspace_id: workspace,
context,
};
assistant.message(params, (err, response) => {
if (err) res.status(500).json(err);
res.json(response);
});
});
try{
//var httpServer = http.createServer(httpApp, app).listen(port);
var httpsServer = https.createServer(options, app).listen(httpsPort);
//httpServer.listen(port, () => console.log(`Running on port ${port}`));
httpsServer.listen(httpsPort, 'exemple1.b.br', () => console.log(`HTTPS Running on port ${httpsPort}`));
console.log(`---------------------------------`);
console.log(`-----------ROBO INICIADO---------`);
console.log(`---------------------------------`);
}catch(err){
console.log(`*********************************`);
console.log(`*****Falha ao iniciar o Robo*****`);
console.log(`*********************************`);
console.log(err);
} */
Chatbot2 app.js:
const AssistantV1 = require('watson-developer-cloud/assistant/v1');
const express = require('express');
const bodyParser = require('body-parser');
const http = require('http');
const https = require('https');
var fs = require('fs');
var httpApp = express();
var workspace;
var options = {
key: fs.readFileSync('certificates/key.pem'),
cert: fs.readFileSync('certificates/server.crt')
};
const app = express();
app.use(bodyParser.json());
app.use(express.static('./public'));
const port = 80;
const httpsPort = 443;
httpApp.set('port', process.env.PORT || 80);
const assistant = new AssistantV1({
username: 'xxxxxxx',
password: 'xxxxxx',
url: 'https://gateway.watsonplatform.net/assistant/api/',
version: '2018-02-16'
});
workspace = 'XXXXXXX'
app.post('/conversation/', (req, res) => {
const { text, context = {} } = req.body;
const params = {
input: { text },
workspace_id: workspace,
context,
};
assistant.message(params, (err, response) => {
if (err) res.status(500).json(err);
res.json(response);
});
});
try{
var httpsServer = https.createServer(options, app).listen(httpsPort);
httpsServer.listen(httpsPort, 'exemple2.b.br', () => console.log(`HTTPS Running on port ${httpsPort}`));
console.log(`---------------------------------`);
console.log(`-----------ROBO INICIADO---------`);
console.log(`---------------------------------`);
}catch(err){
console.log(`*********************************`);
console.log(`*****Falha ao iniciar o Robo*****`);
console.log(`*********************************`);
}
如何“强制”服务器使用其自己的子目录?
答案 0 :(得分:0)
“问题”已解决。
实际上,这是我缺乏有关FQDN实际工作方式的研究,并且应归咎于防病毒。
example2.b.br的URL上不需要“:443”,因为该端口是HTTPS的默认端口。 但是当我使用example1.b.br时,它在({https://example1.b.br:8443)之后需要“:8443”。
至少这个简单的错误使我了解了这一细节。
此后,我发现服务器防病毒软件阻止了某些文件。在端口上创建仅通过Intranet进行通信的异常后,问题得到解决。