๐ข Nginx
Nginx is our recommended web server for Monitron SaaS. It's fast, lightweight, and handles many concurrent connections efficiently โ perfect for a monitoring platform that makes frequent HTTP requests.
๐ Requisitos Previosโ
- Nginx 1.18+ installed
- PHP-FPM installed and running
- SSL certificate (we recommend Let's Encrypt)
๐ Configuration Fileโ
Create a new Nginx server block:
sudo nano /etc/nginx/sites-available/monitron
Paste this configuration:
server {
listen 80;
server_name your-domain.com;
# Redirect all HTTP to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name your-domain.com;
# โโโ SSL Configuration โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# โโโ Document Root โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# ๐จ IMPORTANT: Point to the /public directory!
root /var/www/monitron/public;
index index.php;
# โโโ Character Encoding โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
charset utf-8;
# โโโ Logging โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
access_log /var/log/nginx/monitron-access.log;
error_log /var/log/nginx/monitron-error.log;
# โโโ Request Size โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
client_max_body_size 100M;
# โโโ Main Location Block โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# โโโ PHP Processing โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header X-Powered-By;
# Increase timeouts for long-running AI requests
fastcgi_read_timeout 120;
}
# โโโ Security Headers โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# โโโ Block Hidden Files โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
location ~ /\.(?!well-known).* {
deny all;
}
# โโโ Static File Caching โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, immutable";
try_files $uri =404;
}
# โโโ Deny Access to Sensitive Files โโโโโโโโโโโโโโโโโโโโโโ
location ~ /\.env {
deny all;
return 404;
}
}
๐ง Step-by-Step Setupโ
1. Replace Placeholdersโ
In the config above, replace:
| Marcador | Reemplazar Con |
|---|---|
your-domain.com | Your actual domain name |
/var/www/monitron | Your Monitron installation path |
php8.3-fpm.sock | Your PHP-FPM socket (check with ls /var/run/php/) |
| SSL certificate paths | Your actual certificate paths |
2. Enable the Siteโ
# Create symbolic link to enable the site
sudo ln -s /etc/nginx/sites-available/monitron /etc/nginx/sites-enabled/
# Remove the default site if you don't need it
sudo rm /etc/nginx/sites-enabled/default
3. Test the Configurationโ
sudo nginx -t
You should see:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
4. Restart Nginxโ
sudo systemctl restart nginx
๐ Setting Up SSL with Let's Encryptโ
If you don't have an SSL certificate yet, use Certbot:
# Install Certbot
sudo apt install certbot python3-certbot-nginx
# Obtain certificate (replaces the SSL config automatically)
sudo certbot --nginx -d your-domain.com
# Test auto-renewal
sudo certbot renew --dry-run
Certbot will automatically configure Nginx for SSL!
๐ PHP-FPM Configurationโ
For better performance with many monitors, tune PHP-FPM:
sudo nano /etc/php/8.3/fpm/pool.d/www.conf
Recommended settings:
; Process manager โ dynamic is recommended
pm = dynamic
pm.max_children = 20
pm.start_servers = 5
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.max_requests = 1000
; Timeouts
request_terminate_timeout = 120
; For monitoring many services, increase memory limit
php_admin_value[memory_limit] = 256M
Restart PHP-FPM:
sudo systemctl restart php8.3-fpm
โ Verificar que Funcionaโ
- Visit
https://your-domain.comโ you should be redirected to/install(first time) or/admin(after installation) - Check that
https://your-domain.com/.envreturns a 403 or 404 (security!) - Test a status page URL works:
https://your-domain.com/status/test
๐ ๏ธ Solucion de Problemasโ
502 Bad Gatewayโ
PHP-FPM isn't running or the socket path is wrong:
# Check if PHP-FPM is running
sudo systemctl status php8.3-fpm
# Find the correct socket path
ls /var/run/php/
# Restart PHP-FPM
sudo systemctl restart php8.3-fpm
403 Forbiddenโ
Usually a permissions issue:
sudo chown -R www-data:www-data /var/www/monitron
sudo chmod -R 755 /var/www/monitron
sudo chmod -R 775 /var/www/monitron/storage
Blank White Pageโ
Check the Laravel log:
tail -50 /var/www/monitron/storage/logs/laravel.log