127 lines
3.8 KiB
JavaScript
127 lines
3.8 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 修复重定向问题 ===\n');
|
|
|
|
const config = `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 / {
|
|
try_files \$uri \$uri/ /index.html;
|
|
}
|
|
}
|
|
`;
|
|
|
|
conn.exec('cat > /www/server/panel/vhost/nginx/hs.yifenbao.cn.conf << "ENDOFCONFIG"\n' + config + '\nENDOFCONFIG', (err, stream) => {
|
|
if (err) {
|
|
console.log('写入配置失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream.on('close', () => {
|
|
console.log('配置文件已更新');
|
|
|
|
conn.exec('/www/server/nginx/sbin/nginx -t', (err, stream2) => {
|
|
if (err) {
|
|
console.log('配置检查失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream2.on('data', (data) => {
|
|
console.log('配置检查:', data.toString());
|
|
});
|
|
|
|
stream2.on('close', () => {
|
|
conn.exec('/www/server/nginx/sbin/nginx -s reload', (err, stream3) => {
|
|
if (err) {
|
|
console.log('重启失败:', err.message);
|
|
conn.end();
|
|
return;
|
|
}
|
|
|
|
stream3.on('close', () => {
|
|
console.log('Nginx已重启');
|
|
|
|
setTimeout(() => {
|
|
conn.exec('curl -s -I https://hs.yifenbao.cn/', (err, stream4) => {
|
|
if (err) {
|
|
console.log('测试失败:', err.message);
|
|
} else {
|
|
stream4.on('data', (data4) => {
|
|
console.log('\n根路径响应头:', data4.toString());
|
|
});
|
|
}
|
|
|
|
stream4.on('close', () => {
|
|
conn.end();
|
|
});
|
|
});
|
|
}, 2000);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |