const { Client } = require('ssh2'); const conn = new Client(); const nginxConfig = `server { listen 80; server_name hs.yifenbao.cn; return 301 https://$host$request_uri; } server { listen 443 ssl; 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-RSA-AES256-GCM-SHA384; 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 /admin/ { root /www/huishou; try_files $uri $uri/ /admin/index.html; add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; } location /assets/ { expires 1h; add_header Cache-Control "public, max-age=3600"; } location /static/ { expires 1h; add_header Cache-Control "public, max-age=3600"; } location / { try_files $uri $uri/ /index.html; add_header Cache-Control "no-cache, no-store, must-revalidate"; add_header Pragma "no-cache"; add_header Expires "0"; } } `; conn.on('ready', () => { console.log('=== 更新Nginx配置,添加缓存控制 ==='); conn.exec(`cat > /www/server/panel/vhost/nginx/hs.yifenbao.cn.conf << 'EOF' ${nginxConfig} EOF`, (err) => { if (err) { console.log('写入配置失败:', err); } else { console.log('配置已写入'); conn.exec('/www/server/nginx/sbin/nginx -s reload', () => { console.log('Nginx已重启'); conn.end(); }); } }); }); conn.connect({ host: '101.200.232.171', port: 22, username: 'root', password: 'Torch1112' });