Lesson 7.1: Nginx Installation
In this lesson, you'll install Nginx web server on your Ubuntu system. This is the foundation for your web development project and demonstrates your package management skills.
What is Nginx?
Nginx (pronounced "engine-x") is a high-performance web server that has gained popularity for its efficiency and scalability:
- Web Server: Serves static and dynamic content
- Reverse Proxy: Distributes requests to backend servers
- Load Balancer: Spreads traffic across multiple servers
- HTTP Cache: Improves performance with caching
- SSL/TLS Support: Handles HTTPS encryption
Installing Nginx
We'll use APT to install Nginx, applying what you learned in Module 6:
Update Package Lists
Always start by updating your package lists:
Install Nginx
Install the Nginx web server package:
Verify Installation
Check that Nginx was installed correctly:
Understanding Nginx Structure
After installation, Nginx creates several important directories and files:
Key Directories
- /etc/nginx/: Configuration files
- /var/log/nginx/: Log files
- /var/www/html/: Default website location
- /usr/share/nginx/: Static files and documentation
- /var/cache/nginx/: Cache files
Configuration Files
- /etc/nginx/nginx.conf: Main configuration file
- /etc/nginx/sites-available/: Available site configurations
- /etc/nginx/sites-enabled/: Enabled site configurations
- /etc/nginx/conf.d/: Additional configuration snippets
Starting and Managing Nginx
Use systemctl to manage the Nginx service:
Start Nginx
Check Service Status
Enable Auto-Start
Make Nginx start automatically when system boots:
Stop and Restart
Testing Nginx Installation
Verify that Nginx is working correctly:
Check if Nginx is Running
Test Web Server
Use curl to test the web server:
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.
Thank you for using nginx.
Test in Web Browser
Open your web browser and navigate to:
- http://localhost - Your local machine
- http://127.0.0.1 - Loopback address
- http://your-ip-address - Your actual IP address
ip addr show or hostname -I to find your IP address.
Firewall Configuration
If you have a firewall enabled, you need to allow web traffic:
Check Firewall Status
Allow Web Traffic
Verify Firewall Rules
Troubleshooting Installation Issues
Common problems and solutions:
Port Already in Use
If another web server is running on port 80:
Permission Denied
If you get permission errors:
Service Won't Start
Practice Exercises
Exercise 1: Basic Installation
- Update package lists
- Install Nginx
- Start the Nginx service
- Enable auto-start
- Verify installation with curl
Click for solution
Exercise 2: Service Management
- Check Nginx status
- Stop the Nginx service
- Restart the Nginx service
- View Nginx logs
- Test web server after each operation
Click for solution
What's Next?
Great! You have Nginx installed and running. Next, we'll configure it to serve your own website files.
Key Takeaways
- Use APT to install Nginx web server
- systemctl manages Nginx service (start, stop, restart)
- Nginx configuration is in /etc/nginx/
- Default website files go in /var/www/html/
- Test with curl or web browser
- Configure firewall to allow web traffic
Linux 101