Configuration file
The Nginx configuration is located atnginx/Default.conf and mounted into the web container:
docker-compose.yml:59
Full configuration
nginx/Default.conf
Key settings
Server block
Port on which Nginx listens for HTTP connectionsThis is the internal container port. The
docker-compose.yml maps this to the host’s port 80.Domain name for this server blockCurrently commented out (
#server_name eva.intiinside.com). Uncomment and set your domain for production deployments.Required when using SSL/TLS certificates or hosting multiple sites
Document root directoryNote: Moodle’s actual root is
/var/www/html, not /var/www/html/public. You should change this to:Upload optimization
nginx/Default.conf:8
Maximum size of the client request body (file uploads)This must match or exceed PHP’s
upload_max_filesize and post_max_size settings (both 512M in the Dockerfile).Increase for large video uploads:PHP-FPM timeout
nginx/Default.conf:9
Timeout in seconds for reading a response from the FastCGI server (PHP-FPM)300 seconds (5 minutes) allows time for long-running PHP operations like course backups.Should be less than or equal to PHP’s
max_execution_time (600 seconds in Dockerfile)Slash arguments (critical for Moodle)
nginx/Default.conf:12-14
/course/view.php/123 instead of /course/view.php?id=123.
PHP processing
nginx/Default.conf:17-24
fastcgi_split_path_info: Splits the URI into script name and path info (required for slash arguments)fastcgi_pass app:9000: Forwards PHP requests to theappcontainer on port 9000 (PHP-FPM)SCRIPT_FILENAMEandPATH_INFO: Ensures correct file paths are passed to PHP
Security blocks
nginx/Default.conf:27-30
Modifying Nginx configuration
Common customizations
Enable server name
For production deployments with a domain:Increase upload limit
For large video or backup files:Remember to also increase PHP’s
upload_max_filesize and post_max_size in the DockerfileAdd access logging
HTTP to HTTPS redirect
When SSL is configured (see SSL/HTTPS guide):Custom error pages
Gzip compression
Add compression for better performance:Performance tuning
Worker processes
The base nginx:alpine image uses default worker settings. For high-traffic sites, create a customnginx.conf:
Caching static files
Add browser caching for static assets:Be cautious with aggressive caching during development or frequent theme changes
Troubleshooting
502 Bad Gateway error
502 Bad Gateway error
This means Nginx cannot reach PHP-FPM. Check:
- App container is running:
docker compose ps app - PHP-FPM is listening on port 9000:
docker compose exec app netstat -tlnp | grep 9000 - Containers are on the same network:
docker network inspect ipmoodle_moodle-net fastcgi_passpoints to correct service:app:9000
413 Request Entity Too Large
413 Request Entity Too Large
The uploaded file exceeds Then reload:
client_max_body_size. Increase the limit:docker compose exec web nginx -s reload504 Gateway Timeout
504 Gateway Timeout
PHP script execution exceeded Also ensure PHP’s
fastcgi_read_timeout. Increase the timeout:max_execution_time is at least this value.Nginx configuration test fails
Nginx configuration test fails
Check syntax errors:Common issues:
- Missing semicolons
- Incorrect directive names
- Unclosed blocks (
{without})
Static files not loading (CSS, JS, images)
Static files not loading (CSS, JS, images)
- Check document root is correct:
/var/www/html(not/var/www/html/public) - Verify files exist in volume:
docker compose exec web ls -la /var/www/html/theme - Check file permissions: should be readable by nginx (www-data user)
Next steps
SSL/HTTPS setup
Configure SSL certificates for secure connections
PHP settings
Align PHP timeouts with Nginx settings
Performance monitoring
Monitor Nginx access logs and performance
Scaling
Load balancing with multiple Nginx instances