const { Client } = require('ssh2'); const conn = new Client(); conn.on('ready', () => { console.log('=== 检查容器内部Nginx配置 ==='); conn.exec('docker exec huishou cat /etc/nginx/conf.d/default.conf', (err, stream) => { if (err) { console.log('ERR:', err); conn.end(); return; } let data = ''; stream.on('data', (d) => data += d.toString()); stream.on('close', () => { console.log(data); console.log('\n=== 检查容器内h5目录 ==='); conn.exec('docker exec huishou ls -la /usr/share/nginx/html/', (err2, stream2) => { if (err2) { console.log('ERR2:', err2); conn.end(); return; } stream2.on('data', (d) => console.log(d.toString())); stream2.on('close', () => { console.log('\n=== 检查容器内h5/index.html ==='); conn.exec('docker exec huishou head -5 /usr/share/nginx/html/h5/index.html', (err3, stream3) => { if (err3) { console.log('ERR3:', err3); conn.end(); return; } stream3.on('data', (d) => console.log(d.toString())); stream3.on('close', () => conn.end()); }); }); }); }); }); }); conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' });