Appearance
Nginx Commands
Nginx is the web server that handles all HTTP requests for Zal Ultra. These commands help you manage, troubleshoot, and maintain the Nginx service.
🟠 MEDIUM RISK
Restarting or stopping Nginx will temporarily disconnect all web users. Schedule maintenance during low-traffic periods.
Table of Contents
Service Management
Check Nginx Status
bash
sudo systemctl status nginxPurpose: Shows if Nginx is running, uptime, and recent log entries.
Output Indicators:
active (running)- Service is healthyinactive (dead)- Service is stoppedfailed- Service crashed
Start Nginx
bash
sudo systemctl start nginxPurpose: Starts the Nginx service if it's stopped.
Stop Nginx
🔴 SERVICE OUTAGE
Stopping Nginx will make Zal Ultra completely inaccessible via web browser.
bash
sudo systemctl stop nginxPurpose: Completely stops the Nginx service.
When to use:
- Major configuration changes
- Server maintenance
- Troubleshooting conflicts
Restart Nginx
🟠 BRIEF DOWNTIME
Restart causes a brief interruption (1-2 seconds) for all connected users.
bash
sudo systemctl restart nginxPurpose: Stops and starts Nginx. Use when configuration changes require a full restart.
Reload Nginx (Graceful)
bash
sudo systemctl reload nginxPurpose: Reloads configuration without dropping connections. Preferred method for config changes.
Benefits:
- No downtime
- Existing connections continue
- New connections use new config
Enable Nginx on Boot
bash
sudo systemctl enable nginxPurpose: Ensures Nginx starts automatically when server reboots.
Disable Nginx on Boot
bash
sudo systemctl disable nginxPurpose: Prevents Nginx from starting on boot. Rarely needed.
Configuration Testing
Test Configuration Syntax
bash
sudo nginx -tPurpose: Validates Nginx configuration files for syntax errors.
Always run this before reloading/restarting!
Example Output (Success):
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulExample Output (Error):
nginx: [emerg] unknown directive "servre" in /etc/nginx/sites-enabled/default:10
nginx: configuration file /etc/nginx/nginx.conf test failedShow Nginx Version
bash
nginx -vPurpose: Shows installed Nginx version.
Show Nginx Compile Options
bash
nginx -VPurpose: Shows version and all compile-time options/modules.
Show Current Configuration
bash
sudo nginx -TPurpose: Dumps the full processed configuration (all includes resolved).
Log Management
View Access Logs (Real-time)
bash
sudo tail -f /var/log/nginx/access.logPurpose: Watch incoming requests in real-time.
View Error Logs (Real-time)
bash
sudo tail -f /var/log/nginx/error.logPurpose: Watch errors in real-time. Essential for troubleshooting.
View Last 100 Error Lines
bash
sudo tail -n 100 /var/log/nginx/error.logSearch for Specific Errors
bash
sudo grep "error" /var/log/nginx/error.log | tail -50Clear Nginx Logs
🟠 CAUTION
This deletes log history. Consider backing up logs first.
bash
# Truncate logs (keeps file, clears content)
sudo truncate -s 0 /var/log/nginx/access.log
sudo truncate -s 0 /var/log/nginx/error.log
# Or rotate logs properly
sudo logrotate -f /etc/logrotate.d/nginxCheck Log File Sizes
bash
sudo du -sh /var/log/nginx/*Performance Monitoring
Check Active Connections
bash
# If stub_status module is enabled
curl http://localhost/nginx_status
# Or check with netstat
sudo netstat -an | grep :80 | wc -l
sudo netstat -an | grep :443 | wc -lCheck Nginx Process Memory Usage
bash
ps aux | grep nginxCheck Worker Processes
bash
ps -ef | grep nginxExpected output: One master process and multiple worker processes.
Troubleshooting
Common Issues and Solutions
Port Already in Use
bash
# Find what's using port 80
sudo lsof -i :80
sudo netstat -tlnp | grep :80
# Kill the process if needed
sudo kill -9 <PID>Permission Denied Errors
bash
# Fix ownership
sudo chown -R www-data:www-data /var/www/html
# Fix permissions
sudo chmod -R 755 /var/www/html
sudo chmod -R 775 /var/www/html/storage502 Bad Gateway
bash
# Usually means PHP-FPM is down
sudo systemctl status php8.3-fpm
sudo systemctl restart php8.3-fpm504 Gateway Timeout
bash
# Check PHP-FPM and increase timeouts if needed
sudo nano /etc/nginx/sites-available/default
# Increase: fastcgi_read_timeout 300;
sudo nginx -t && sudo systemctl reload nginxCheck Nginx Configuration Files
bash
# Main config
sudo nano /etc/nginx/nginx.conf
# Site configs
ls -la /etc/nginx/sites-available/
ls -la /etc/nginx/sites-enabled/
# View default site config
sudo nano /etc/nginx/sites-available/defaultQuick Reference Card
| Action | Command |
|---|---|
| Check status | sudo systemctl status nginx |
| Start | sudo systemctl start nginx |
| Stop | sudo systemctl stop nginx |
| Restart | sudo systemctl restart nginx |
| Reload (graceful) | sudo systemctl reload nginx |
| Test config | sudo nginx -t |
| View errors | sudo tail -f /var/log/nginx/error.log |
| View access | sudo tail -f /var/log/nginx/access.log |
