Exercise 1: Basic Installation and Setup
- Install NGINX on your system
- Verify the installation with
nginx -v - Start NGINX service
- Access the default NGINX page in your browser
- Stop and restart NGINX
- Test configuration with
nginx -t
Exercise 2: Basic Server Configuration
- Create a directory
/var/www/mysite - Create an
index.htmlfile in that directory - Create a server block configuration to serve files from
/var/www/mysite - Set the server name to
mysite.local - Test and reload the configuration
- Access your site in the browser (may need to add to
/etc/hosts)
Exercise 3: Serving Static Files
- Create a website with HTML, CSS, JavaScript, and images
- Configure NGINX to serve all these file types
- Set up caching for images (1 year)
- Set up caching for CSS and JS files (30 days)
- Test file serving and caching headers
Exercise 4: Multiple Server Blocks
- Create two different websites in separate directories
- Configure two server blocks for different domains:
-
site1.local-site2.local - Test that each domain serves the correct content
- Create a default server block that returns 444
Exercise 5: Directory Listings
- Create a directory
/var/www/downloadswith some files - Configure NGINX to enable directory listing for
/downloads - Set directory listing to show file sizes in human-readable format
- Test directory listing in browser
- Disable directory listing for other locations
Exercise 6: Error Pages
- Create custom 404.html and 50x.html error pages
- Configure NGINX to use these custom error pages
- Test 404 error by accessing non-existent page
- Test 50x error (you may need to simulate backend error)
Exercise 7: File Permissions
- Create a website directory
- Set proper ownership (nginx user)
- Set proper permissions (755 for directories, 644 for files)
- Test that NGINX can serve the files
- Try incorrect permissions and see what errors occur
Exercise 8: Configuration File Organization
- Create separate configuration files in
/etc/nginx/conf.d/ - Create one file for each website
- Ensure all files are included in main
nginx.conf - Test that all configurations work
- Practice enabling/disabling sites