104 lines
4.0 KiB
JavaScript
104 lines
4.0 KiB
JavaScript
const { Client } = require('ssh2');
|
|
|
|
const conn = new Client();
|
|
const nginxConfig = `server {
|
|
listen 80;
|
|
server_name hs.yifenbao.cn;
|
|
return 301 https://$server_name$request_uri;
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl http2;
|
|
server_name hs.yifenbao.cn;
|
|
|
|
ssl_certificate /www/server/panel/vhost/cert/hs.yifenbao.cn/fullchain.pem;
|
|
ssl_certificate_key /www/server/panel/vhost/cert/hs.yifenbao.cn/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK;
|
|
ssl_prefer_server_ciphers on;
|
|
ssl_session_cache shared:SSL:10m;
|
|
ssl_session_timeout 10m;
|
|
|
|
root /www/huishou/dist/build/h5;
|
|
index index.html;
|
|
|
|
location /api/ {
|
|
proxy_pass http://127.0.0.1:4000/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;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
|
|
location /icons/ {
|
|
proxy_pass http://127.0.0.1:4000/icons/;
|
|
proxy_set_header Host $host;
|
|
}
|
|
|
|
location /admin/ {
|
|
root /www/huishou;
|
|
try_files $uri $uri/ /admin/index.html;
|
|
}
|
|
|
|
location /assets/ {
|
|
expires 1h;
|
|
add_header Cache-Control "public";
|
|
}
|
|
|
|
location /static/ {
|
|
expires 1h;
|
|
add_header Cache-Control "public";
|
|
}
|
|
|
|
location / {
|
|
proxy_pass http://127.0.0.1:4000/;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}
|
|
}
|
|
`;
|
|
|
|
conn.on('ready', () => {
|
|
conn.sftp((err, sftp) => {
|
|
if (err) { console.log('SFTP err:', err); conn.end(); return; }
|
|
const ws = sftp.createWriteStream('/www/server/panel/vhost/nginx/hs.yifenbao.cn.conf');
|
|
ws.on('close', () => {
|
|
console.log('配置已更新');
|
|
sftp.end();
|
|
conn.exec('/www/server/nginx/sbin/nginx -t', (err2, stream) => {
|
|
if (err2) { console.log('配置检查失败:', err2); conn.end(); return; }
|
|
stream.on('data', (d) => console.log('配置检查:', d.toString()));
|
|
stream.on('close', (code) => {
|
|
if (code === 0) {
|
|
conn.exec('/www/server/nginx/sbin/nginx -s reload', (err3, stream2) => {
|
|
stream2.on('data', (d) => console.log('重启:', d.toString()));
|
|
stream2.on('close', () => {
|
|
console.log('\n=== 测试 ===');
|
|
conn.exec('curl -s -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64)" https://hs.yifenbao.cn/ | head -5', (err4, stream3) => {
|
|
if (err4) { console.log('ERR4:', err4); }
|
|
else { stream3.on('data', (d) => console.log('桌面浏览器:\n', d.toString())); }
|
|
stream3.on('close', () => {
|
|
conn.exec('curl -s -A "Mozilla/5.0 (iPhone; CPU iPhone OS 16_0 like Mac OS X)" https://hs.yifenbao.cn/ | head -5', (err5, stream4) => {
|
|
if (err5) { console.log('ERR5:', err5); }
|
|
else { stream4.on('data', (d) => console.log('手机浏览器:\n', d.toString())); }
|
|
stream4.on('close', () => conn.end());
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
} else {
|
|
console.log('配置有误');
|
|
conn.end();
|
|
}
|
|
});
|
|
});
|
|
});
|
|
ws.write(nginxConfig);
|
|
ws.end();
|
|
});
|
|
});
|
|
|
|
conn.connect({ host: 'hs.yifenbao.cn', port: 22, username: 'root', password: 'Torch1112' }); |