我正在尝试让我的Plesk NodeJS Express应用程序与同一服务器上的mySQL数据库表建立连接
我正在Ubuntu服务器上运行最新的Plesk。
我有一个域(domain.com)和一个名为api.domain.com的子域
我已经通过界面为api.domain.com安装了一个nodejs应用程序,并且该应用程序正在运行,只要不查询数据库,它就会返回示例路由返回数据。
我已经在domain.com下安装了一个数据库,并且在该界面还显示附加域的一侧显示api.domain.com。
我尝试从本地计算机以及节点应用程序连接到该数据库,但是它在本地不起作用,并且我假设它也不能从节点应用程序连接。
我检查了var / log / apache2 / logs / error.log,它似乎没有在nodejs应用程序的开始时为初始连接引发错误:
const connection = mysql.createConnection({
host: 'localhost',
user: 'admin',
password: 'secretpassword',
database: 'app',
});
connection.connect(err => {
if (err) throw err;
console.log('Connected!');
});
因为在error.log中,它确实显示已连接!似乎有联系吗?
但是在我的测试路线中,除了“浏览器无法获取/ people / 1”外,什么都没有显示 我还在应用程序数据库的人员表中添加了2行数据。
app.get('people/:id', (req, res) => {
console.log('Fetching data with id' + req.params.id);
const id = req.params.id;
const queryString = "SELECT * FROM people WHERE id = ?";
connection.query(queryString, [id], (err, rows, fields) =>
{
console.log('I think we fetched'); // this does not show
res.json(rows);
});
});
在用户的数据库管理中,将其设置为“允许来自任何主机的远程连接”
在防火墙屏幕上,似乎允许所有传入连接:
FTP server passive ports Allow incoming from all
Customer & Business Manager payment gateways Allow incoming from all
Single Sign-On Allow incoming from all
Plesk Installer Allow incoming from all
Plesk administrative interface Allow incoming from all
WWW server Allow incoming from all
FTP server Allow incoming from all
SSH (secure shell) server Allow incoming from all
SMTP (submission port) server Allow incoming from all
SMTP (mail sending) server Allow incoming from all
POP3 (mail retrieval) server Allow incoming from all
IMAP (mail retrieval) server Allow incoming from all
Mail password change service Allow incoming from all
MySQL server Allow incoming from all
PostgreSQL server Allow incoming from all
Samba (file sharing in Windows networks) Allow incoming from all
Plesk VPN Allow incoming from all
Domain name server Allow incoming from all
IPv6 Neighbor Discovery Allow incoming from all
Ping service Allow incoming from all