From a6887106da873547eb0fdcb2bfe40f809ec65aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cmit=20Tun=C3=A7?= Date: Sun, 29 Mar 2026 00:37:56 +0300 Subject: [PATCH] feat: implement Nginx project configuration generation and service management IPC handlers --- config/nginx_project.conf.template | 21 ++++++++++++++++ logs/nginx.pid | 2 +- src/main/ipc/index.ts | 40 ++++++++++++++++-------------- 3 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 config/nginx_project.conf.template diff --git a/config/nginx_project.conf.template b/config/nginx_project.conf.template new file mode 100644 index 0000000..896f87a --- /dev/null +++ b/config/nginx_project.conf.template @@ -0,0 +1,21 @@ +location /{{HOST}}/ { + alias "{{PATH}}/"; + index index.php index.html; + + # Try the literal URI, then directory, then fallback to index.php + try_files $uri $uri/ /{{HOST}}/index.php?$query_string; + + # PHP handling nested INSIDE the alias location to maintain context + location ~ \.php$ { + fastcgi_pass 127.0.0.1:{{PHP_PORT}}; + fastcgi_index index.php; + + # Correctly split path to get the relative script path + fastcgi_split_path_info ^/{{HOST}}(.+\.php)(.*)$; + fastcgi_param SCRIPT_FILENAME "{{PATH}}$fastcgi_script_name"; + fastcgi_param DOCUMENT_ROOT "{{PATH}}"; + fastcgi_param PATH_INFO $fastcgi_path_info; + + include "{{CONF_DIR}}/fastcgi_params"; + } +} diff --git a/logs/nginx.pid b/logs/nginx.pid index a8eeab3..4ce918a 100644 --- a/logs/nginx.pid +++ b/logs/nginx.pid @@ -1 +1 @@ -48324 +38592 diff --git a/src/main/ipc/index.ts b/src/main/ipc/index.ts index ce17774..5835969 100644 --- a/src/main/ipc/index.ts +++ b/src/main/ipc/index.ts @@ -56,27 +56,29 @@ export function registerIpcHandlers(): void { } const projects = await projectService.getProjects() - const projectLocations = projects.map(p => { + const projectsConfDir = path.join(configService.getBasePath(), 'generated_configs', 'projects') + if (!fs.existsSync(projectsConfDir)) fs.mkdirSync(projectsConfDir, { recursive: true }) + + // Clean up old project configs + const existingFiles = fs.readdirSync(projectsConfDir) + for (const file of existingFiles) { + fs.unlinkSync(path.join(projectsConfDir, file)) + } + + for (const p of projects) { const phpPort = portMappingService.getPhpPort(p.phpVersion) const normalizedPath = p.path.replace(/\\/g, '/') - return ` - location /${p.host}/ { - alias "${normalizedPath}/"; - index index.php index.html; - try_files $uri $uri/ /${p.host}/index.php?$query_string; + await configService.generateConfig('nginx_project.conf.template', `projects/${p.host}.conf`, { + HOST: p.host, + PATH: normalizedPath, + PHP_PORT: phpPort.toString(), + CONF_DIR: confDir.replace(/\\/g, '/') + }) + } - # Sadece .php değil, URI'nin tamamını eşleştirip dosya adını $1 içine alıyoruz - location ~ ^/${p.host}/(.*\.php)$ { - fastcgi_pass 127.0.0.1:${phpPort}; - fastcgi_index index.php; - - # Hatalı olan $request_filename yerine manuel path veriyoruz - fastcgi_param SCRIPT_FILENAME "${normalizedPath}/$1"; - - include "${confDir.replace(/\\/g, '/')}/fastcgi_params"; - } -}` - }).join('\n') + const projectsInclusion = projects.length > 0 + ? `include "${projectsConfDir.replace(/\\/g, '/')}/*.conf";` + : '' const configPath = await configService.generateConfig('nginx.conf.template', 'nginx.conf', { PORT: settings.nginxPort, @@ -85,7 +87,7 @@ export function registerIpcHandlers(): void { LOG_DIR: logDir.replace(/\\/g, '/'), CONF_DIR: confDir.replace(/\\/g, '/'), PHPMYADMIN_DIR: phpMyAdminService.getPath().replace(/\\/g, '/'), - PROJECTS: projectLocations + PROJECTS: projectsInclusion }) // Test config first with prefix