Installation
Run composer require baks-dev/nginx-unit in your Laravel project.
Ensure your project uses PHP 8.4+ and Laravel 10.x+ (verify via php -v and laravel --version).
Publish Config & Assets Execute:
php artisan vendor:publish --provider="BaksDev\NginxUnit\NginxUnitServiceProvider" --tag="config"
php artisan vendor:publish --provider="BaksDev\NginxUnit\NginxUnitServiceProvider" --tag="assets"
This generates:
config/nginx-unit.php (configuration)public/nginx-unit/.First Use Case: Local Development
config/nginx-unit.php with your local Unit server details (e.g., unit_socket).php artisan nginx-unit:deploy
This deploys a default configuration to your Unit server.
config/nginx-unit.php (adjust unit_socket, server_name, and upstream settings).php artisan list → Filter for nginx-unit: commands (e.g., deploy, reload, status).storage/logs/nginx-unit.log for deployment/reload errors.Local Development
php artisan nginx-unit:deploy to sync config to Unit./api/health) via curl http://localhost:8080/health.php artisan nginx-unit:reload
CI/CD Integration
php artisan nginx-unit:deploy --env=production
--force to overwrite existing configs if needed.Dynamic Configuration
// app/Providers/NginxUnitServiceProvider.php
public function boot()
{
$this->app->bind('nginx-unit.template', function () {
return new CustomTemplateRenderer();
});
}
resources/views/vendor/nginx-unit/.Health Checks
Route::get('/nginx-unit/health', function () {
return response()->json(['status' => NginxUnit::status()]);
});
nginx-unit:queue command.storage/nginx-unit/config to your Unit container’s config directory.Socket Permissions
www-data) has read/write access to the unit_socket path.chmod 777 /var/run/nginx-unit.sock (temporary; adjust permissions in production).Config Validation
php artisan nginx-unit:validate
Certbot Integration
certbot certonly --webroot -w public/ -d yourdomain.com
nginx-unit.php to point to the cert paths.PHP-FPM vs. Unit
journalctl -u nginx-unit -f # Systemd
# OR
cat /var/log/nginx/unit.log
--dry-run with nginx-unit:deploy to preview changes:
php artisan nginx-unit:deploy --dry-run
Custom Config Templates
vendor/baks-dev/nginx-unit/src/ConfigTemplates/ in your project.custom.conf template for API-specific routes.Event Listeners
nginx-unit.deployed events:
public function handle(NginxUnitDeployed $event)
{
Log::info('Unit config deployed to ' . $event->serverName);
}
Unit API Extensions
NginxUnit facade to interact with Unit’s API:
$status = NginxUnit::status(); // Returns server status
$config = NginxUnit::getConfig('api'); // Fetch a specific config
NGINX_UNIT_ (e.g., NGINX_UNIT_SERVER_NAME=api.local).8080 for HTTP. Change in config/nginx-unit.php:
'ports' => [
'http' => 8080,
'https' => 8443,
],
ssl_certificate and ssl_certificate_key paths are correct and files are readable.How can I help you explore Laravel packages today?