38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
const { Client } = require('ssh2');
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
const config = `server {
|
|
listen 80;
|
|
server_name hs.yifenbao.cn;
|
|
|
|
location /h5/ {
|
|
proxy_pass http://127.0.0.1:4001/h5/;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
}
|
|
|
|
location /api/ {
|
|
proxy_pass http://127.0.0.1:4001/api/;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
}
|
|
}
|
|
`;
|
|
|
|
conn.exec(`cat > /www/server/panel/vhost/nginx/hs.yifenbao.cn.conf << 'EOF'\n${config}EOF`, (err, stream) => {
|
|
if (err) { console.log('ERR:', err); conn.end(); return; }
|
|
stream.on('close', () => {
|
|
conn.exec('/www/server/nginx/sbin/nginx -t && /www/server/nginx/sbin/nginx -s reload', (err2, stream2) => {
|
|
if (err2) { console.log('ERR2:', err2); conn.end(); return; }
|
|
stream2.on('data', (d) => console.log('OUT:', d.toString()));
|
|
stream2.on('close', () => conn.end());
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' }); |