forked from urvishpatelce/lxd-app
95 lines
2.7 KiB
Nginx Configuration File
95 lines
2.7 KiB
Nginx Configuration File
server {
|
|
listen 8080;
|
|
server_name lxdapp.local *.lxdapp.local;
|
|
|
|
root /var/www/html/lxd-app/backend/app/public;
|
|
index index.php index.html;
|
|
|
|
access_log /var/log/nginx/lxdapp.access.log;
|
|
error_log /var/log/nginx/lxdapp.error.log;
|
|
|
|
location / {
|
|
try_files $uri /index.php$is_args$args;
|
|
}
|
|
|
|
location ~ \.php$ {
|
|
try_files $uri =404;
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
include fastcgi_params;
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
|
fastcgi_index index.php;
|
|
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
|
|
}
|
|
|
|
location ~ /\.ht {
|
|
deny all;
|
|
}
|
|
}
|
|
|
|
|
|
server {
|
|
listen 8081 ssl;
|
|
server_name lxdapp.local;
|
|
|
|
ssl_certificate /etc/ssl/certs/lxdapp.local.crt;
|
|
ssl_certificate_key /etc/ssl/private/lxdapp.local.key;
|
|
|
|
root /var/www/html/lxd-app/backend/app/public;
|
|
index index.php index.html;
|
|
|
|
access_log /var/log/nginx/lxdapp.access.log;
|
|
error_log /var/log/nginx/lxdapp.error.log;
|
|
|
|
location / {
|
|
try_files $uri /index.php$is_args$args;
|
|
}
|
|
|
|
location ~ \.php$ {
|
|
try_files $uri =404;
|
|
fastcgi_split_path_info ^(.+\.php)(/.+)$;
|
|
include fastcgi_params;
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
|
|
fastcgi_index index.php;
|
|
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
|
|
}
|
|
|
|
location ~ /\.ht {
|
|
deny all;
|
|
}
|
|
}
|
|
|
|
public function forward(Request $request, Response $response)
|
|
{
|
|
$source = $request->getQueryParams()['source'] ?? null;
|
|
$domain = $request->getUri()->getHost(); // e.g. customer1.lxdapp.local
|
|
|
|
$name = $this->mapDomainToContainer($domain); // Use your config mapping
|
|
$ip = $this->getContainerIP($name);
|
|
|
|
if ($source === 'login') {
|
|
// Trigger provisioning if requested from login
|
|
if (!$this->containerExists($name)) {
|
|
$this->createContainer($name);
|
|
$this->startContainer($name);
|
|
$this->installPackages($name);
|
|
|
|
// Wait for container to be ready
|
|
if (!$this->waitForPort($ip, 80)) {
|
|
return $this->json($response, ['status' => 'error', 'message' => 'Container not ready'], 500);
|
|
}
|
|
}
|
|
|
|
return $this->json($response, ['status' => 'success', 'ip' => $ip]);
|
|
}
|
|
|
|
// For non-login (main page access)
|
|
if (!$this->containerExists($name)) {
|
|
return $this->json($response, ['status' => 'not-found']);
|
|
}
|
|
|
|
// Otherwise proxy the request to container (assuming already up)
|
|
return $this->proxyToContainer($request, $response, $ip);
|
|
}
|