Author: Madhan Gopalakrishnan | Published on : 19-02-2025
Linux Server Administration is a crucial skill for web hosting, application deployment, and network management. This guide will take you through the essential steps of setting up and managing web servers in a Linux environment.
🛠️ Web Servers Overview
A web server is a system that serves web pages to users based on their requests via a browser. The two most popular web servers in Linux are:
| Web Server | Description |
|---|---|
| Apache 🌍 | Feature-rich, highly configurable, and widely used |
| Nginx ⚡ | High-performance, lightweight, and ideal for handling many concurrent connections |
🌐 Setting Up an Apache Web Server
1️⃣ Install Apache
sudo apt update
sudo apt install apache2 -y
2️⃣ Start and Enable Apache
sudo systemctl start apache2
sudo systemctl enable apache2
3️⃣ Check Apache Status
sudo systemctl status apache2
4️⃣ Configure Apache Virtual Hosts (Multiple Sites on a Single Server)
Virtual Hosts allow multiple websites on a single server.
- Create a configuration file for each site:
sudo nano /etc/apache2/sites-available/site1.conf
- Add the following:
<VirtualHost *:80>
ServerName site1.com
DocumentRoot /var/www/site1
<Directory /var/www/site1>
AllowOverride All
</Directory>
</VirtualHost>
- Repeat for
site2.com:
sudo nano /etc/apache2/sites-available/site2.conf
- Enable both sites and restart Apache:
sudo a2ensite site1.conf
sudo a2ensite site2.conf
sudo systemctl restart apache2
🔑 SSL Offloading with Apache
SSL offloading is used to handle encryption/decryption at the reverse proxy level to reduce server load.
- Install Certbot for SSL Certificates:
sudo apt install certbot python3-certbot-apache
- Generate and Apply SSL Certificates:
sudo certbot --apache -d site1.com -d site2.com
- Modify the Apache Virtual Host configuration to enable SSL termination:
sudo nano /etc/apache2/sites-available/site1-le-ssl.conf
- Ensure the configuration contains:
<VirtualHost *:443>
ServerName site1.com
DocumentRoot /var/www/site1
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/site1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site1.com/privkey.pem
</VirtualHost>
- Enable the SSL module and restart Apache:
sudo a2enmod ssl
sudo systemctl restart apache2
- Auto-Renew SSL:
sudo certbot renew --dry-run
⚡ Setting Up an Nginx Web Server
1️⃣ Install Nginx
sudo apt update
sudo apt install nginx -y
2️⃣ Start and Enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx
3️⃣ Check Nginx Status
sudo systemctl status nginx
4️⃣ Configure Nginx Server Blocks (Multiple Sites on a Single Server)
- Create a new configuration file for each site:
sudo nano /etc/nginx/sites-available/site1
- Add the following content:
server {
listen 80;
server_name site1.com;
root /var/www/site1;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
- Repeat for
site2.com:
sudo nano /etc/nginx/sites-available/site2
- Enable both configurations and restart Nginx:
sudo ln -s /etc/nginx/sites-available/site1 /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/site2 /etc/nginx/sites-enabled/
sudo systemctl restart nginx
🔑 SSL Offloading with Nginx
SSL offloading is used to handle encryption/decryption at the reverse proxy level to reduce server load.
- Install Certbot for SSL Certificates:
sudo apt install certbot python3-certbot-nginx
- Generate and Apply SSL Certificates:
sudo certbot --nginx -d site1.com -d site2.com
- Auto-Renew SSL:
sudo certbot renew --dry-run
📊 Monitoring Apache and Nginx with Grafana
1️⃣ Install Grafana
sudo apt update
sudo apt install -y grafana
2️⃣ Start and Enable Grafana
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
3️⃣ Install and Configure Prometheus for Data Collection
sudo apt install prometheus -y
Modify /etc/prometheus/prometheus.yml and add:
scrape_configs:
- job_name: 'apache'
static_configs:
- targets: ['localhost:9117']
- job_name: 'nginx'
static_configs:
- targets: ['localhost:9113']
Restart Prometheus:
sudo systemctl restart prometheus
4️⃣ Install Exporters for Apache and Nginx
Apache Exporter:
sudo apt install prometheus-apache-exporter
sudo systemctl start prometheus-apache-exporter
sudo systemctl enable prometheus-apache-exporter
Nginx Exporter:
sudo apt install prometheus-nginx-exporter
sudo systemctl start prometheus-nginx-exporter
sudo systemctl enable prometheus-nginx-exporter
5️⃣ Add Prometheus as a Data Source in Grafana
- Open Grafana at
http://your_server_ip:3000 - Login (default: admin/admin)
- Navigate to
Configuration -> Data Sources - Add a new
Prometheusdata source and enterhttp://localhost:9090
6️⃣ Create Dashboards for Monitoring
- Go to
Create -> Dashboard - Add a new panel
- Use Prometheus queries like:
apache_requests_total
nginx_connections_active
- Save and visualize Apache/Nginx performance!
✅ Conclusion
By following this guide, you now have a working web server setup using Apache or Nginx on Linux with SSL offloading. Understanding these configurations and security measures will help you deploy and manage web applications efficiently. 🚀
Would you like additional details on database integration or further security hardening? 🤔









