Updated nginx configs, removed middleware

This commit is contained in:
Asa Yee 2025-12-15 12:10:44 -04:00
parent 1670da55e9
commit 178aef3d05
3 changed files with 65 additions and 50 deletions

View file

@ -1,35 +0,0 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
class ApplyForwardedPrefix
{
public function handle(Request $request, Closure $next)
{
$prefix = "/hosp";
if ($prefix) {
// Normalize prefix to "/hosp" (no trailing slash)
$prefix = '/' . ltrim($prefix, '/');
$prefix = rtrim($prefix, '/');
// If Apache stripped /hosp before proxying, Laravel sees "/livewire/..."
// Re-inject the prefix into REQUEST_URI so URL generation/signing aligns with the browser URL.
$uri = $request->server->get('REQUEST_URI'); // includes query string
if (is_string($uri) && $uri !== '' && !str_starts_with($uri, $prefix . '/')) {
$request->server->set('REQUEST_URI', $prefix . $uri);
}
// Help Symfony compute the base URL.
$scriptName = $request->server->get('SCRIPT_NAME') ?: '';
if ($scriptName !== '' && !str_starts_with($scriptName, $prefix . '/')) {
$request->server->set('SCRIPT_NAME', $prefix . $scriptName);
}
}
return $next($request);
}
}

65
citadel.conf Normal file
View file

@ -0,0 +1,65 @@
# cat /etc/nginx/conf.d/citadel.conf
server {
listen 80;
server_name citadel.msya.gov.tt;
# --- Main Site Configuration ---
# This is the default root for your server
root /var/www/html;
index index.php index.html index.htm;
# This handles requests for your main site
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# This handles PHP requests for your main site
location ~ \.php$ {
# This condition prevents this block from incorrectly handling phpMyAdmin requests
if ($request_uri ~ ^/phpmyadmin) {
return 404;
}
try_files $uri =404;
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
# --- Hospitality App Configuration ---
location /hosp {
alias /var/www/html/hosp_2025/public;
index index.php;
# If file/dir doesn't exist, rewrite to index.php (Laravel routing)
if (!-e $request_filename) {
rewrite ^ /hosp/index.php last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
# --- phpMyAdmin Configuration ---
# This location block uses 'alias' to correctly point to the phpMyAdmin files
location /phpmyadmin {
alias /usr/share/phpMyAdmin/; # Correct directive
index index.php;
try_files $uri $uri/ /phpmyadmin/index.php?$query_string;
# This nested location handles ONLY the PHP files inside the aliased directory
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
# Use $request_filename because 'alias' is used
fastcgi_param SCRIPT_FILENAME $request_filename;
}
}
# Deny access to sensitive phpMyAdmin directories
location ~ ^/phpmyadmin/(sql|setup)/ {
deny all;
}
}

View file

@ -1,15 +0,0 @@
Listen 25120
<VirtualHost 127.0.0.1:25120>
ServerName jedi.msya.gov.tt
DocumentRoot /var/www/html/hosp_2025/public
<Directory /var/www/html/hosp_2025/public>
AllowOverride All
Require all granted
Options FollowSymLinks
</Directory>
ErrorLog /var/log/httpd/hosp_2025_error.log
CustomLog /var/log/httpd/hosp_2025_access.log combined
</VirtualHost>