إنتقل إلى المحتوى الرئيسي

🟢 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.


📋 المتطلبات الأساسية

  • 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:

العنصر النائباستبدل بـ
your-domain.comYour actual domain name
/var/www/monitronYour Monitron installation path
php8.3-fpm.sockYour PHP-FPM socket (check with ls /var/run/php/)
SSL certificate pathsYour 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

✅ التحقق من أنه يعمل

  1. Visit https://your-domain.com — you should be redirected to /install (first time) or /admin (after installation)
  2. Check that https://your-domain.com/.env returns a 403 or 404 (security!)
  3. Test a status page URL works: https://your-domain.com/status/test

🛠️ استكشاف الأخطاء وإصلاحها

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