116 lines
3.7 KiB
JavaScript
116 lines
3.7 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 更新Nginx配置 ===\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;
|
|
|
|
proxy_connect_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
|
|
add_header X-Frame-Options SAMEORIGIN;
|
|
add_header X-Content-Type-Options nosniff;
|
|
add_header X-XSS-Protection "1; mode=block";
|
|
|
|
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;
|
|
proxy_set_header X-Forwarded-Host \$host;
|
|
proxy_set_header X-Forwarded-Port \$server_port;
|
|
}
|
|
|
|
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/ {
|
|
proxy_pass http://127.0.0.1:4000/admin/;
|
|
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.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已重启');
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |