From 4f999094f30574d44ec4e8845f88f1966f7ac881 Mon Sep 17 00:00:00 2001 From: Alexey Berezhok Date: Wed, 20 May 2026 23:24:30 +0300 Subject: [PATCH] Fixes --- bin/v-bunkerweb-migrate | 133 +++++++++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 37 deletions(-) diff --git a/bin/v-bunkerweb-migrate b/bin/v-bunkerweb-migrate index 972cc03..c9beb9f 100755 --- a/bin/v-bunkerweb-migrate +++ b/bin/v-bunkerweb-migrate @@ -69,6 +69,74 @@ def log_migrate_stage(stage) end end +# Function to parse and migrate nginx.conf from /usr/local/hestia/nginx-system/etc/nginx/nginx.conf +def migrate_nginx_config_from_file(source_path) + return false unless File.exist?(source_path) + + hestia_print_info_message_to_cli "Processing nginx config from: #{source_path}" + + content = File.read(source_path) + original_content = content.dup + + modified = false + + # Replace all paths starting with /var/ to /usr/local/hestia/nginx-system/var/ + # This pattern matches any absolute path that starts with /var/ anywhere in the line + content = content.gsub(/\/var\//, '/usr/local/hestia/nginx-system/var/') + + # Replace pid path from /run/nginx.pid to /run/nginx-system.pid + content = content.gsub(/pid\s+\S+/) { |match| match.gsub('/run/nginx.pid', '/run/nginx-system.pid') } + + if content != original_content + File.write(source_path, content) + hestia_print_info_message_to_cli "Updated config: #{source_path}" + modified = true + end + + modified +end + +def parse_listen(line) + # Попытка найти IP:port + m = line.match(/^\s*listen\s+([^\s:]+):(\d+)/i) + return [m[1], m[2]] if m + # Если только порт после listen + m = line.match(/^\s*listen\s+(\d+);?\s*$/i) + return [nil, m[1]] if m + nil +end + +# Helper function to parse and replace ports in listen directives using temp placeholders +def parse_and_replace_listen_directive(line, proxy_port, proxy_ssl_port) + return line unless line.match?(/\blisten\b/i) + + new_line = line.dup + + # Define target ports (always migrate to these values regardless of input) + target_http_port = '8078' + target_ssl_port = '8079' + + result = parse_listen(line) + return line unless result + ip, port = result + + if port == proxy_port + if ip + new_line.gsub!("#{ip}:#{port}", "#{ip}:#{target_http_port}") + else + new_line.gsub!(port, target_http_port) + end + elsif port == proxy_ssl_port + if ip + new_line.gsub!("#{ip}:#{port}", "#{ip}:#{target_ssl_port}") + else + new_line.gsub!(port, target_ssl_port) + end + end + + new_line +end + hestia_check_privileged_user load_global_bash_variables "/etc/hestiacp/hestia.conf" @@ -175,12 +243,25 @@ when :migratenginx end end end + log_migrate_stage('stage4.1') do + # Parse nginx.conf file to replace paths + if migrate_nginx_config_from_file("/usr/local/hestia/nginx-system/etc/nginx/nginx.conf") + hestia_print_info_message_to_cli "Completed migration of nginx.conf paths" + else + hestia_print_error_message_to_cli "Warning: Could not migrate nginx.conf from #{File.expand_path('/usr/local/hestia/nginx-system/etc/nginx/nginx.conf')}" + end + end log_migrate_stage('stage5') do nginx_conf_dir = '/usr/local/hestia/nginx-system/etc/nginx' # Read proxy ports from configuration - proxy_port = $PROXY_PORT.nil? || $PROXY_PORT.empty? ? '80' : $PROXY_PORT - proxy_ssl_port = $PROXY_SSL_PORT.nil? || $PROXY_SSL_PORT.empty? ? '443' : $PROXY_SSL_PORT + #proxy_port = $PROXY_PORT.nil? || $PROXY_PORT.empty? ? '80' : $PROXY_PORT + #proxy_ssl_port = $PROXY_SSL_PORT.nil? || $PROXY_SSL_PORT.empty? ? '443' : $PROXY_SSL_PORT + + proxy_port = '80' + proxy_ssl_port = '443' + + hestia_print_info_message_to_cli "Migrating ports: #{proxy_port} -> 8078, #{proxy_ssl_port} -> 8079" # Find and replace port in all .conf files Dir.glob(File.join(nginx_conf_dir, '**', '*.conf')).each do |conf_file| @@ -188,52 +269,30 @@ when :migratenginx content = File.read(conf_file) modified = false - # Replace HTTP port pattern: listen :#{$PROXY_PORT} [flags]; - # Matches: listen 192.168.3.81:80; or listen 192.168.3.81:80 default_server; - new_content = content.gsub(/(?:#{$PROXY_SSL_PORT} ssl; - if new_content == content - new_content = content.gsub(/(?