Exploring Web Server Configurations for Different Use Cases 🌐

Exploring Web Server Configurations for Different Use Cases 🌐

πŸ“Introduction:

In the world of web hosting and applications, the choice of a web server plays a crucial role in determining the performance, security, and accessibility of your online presence. Let's dive into the setup of three popular web serversβ€”nginx, HAProxy, and Apache 2β€”each tailored to distinct use cases. πŸš€

Ejecutar Apache Nginx y HAProxy en el mismo servidor ubuntu 20.04 -  Tecnolitas

Nginx - Restricting Access Using nginx.conf 🚧

Use Case: Control Access to Sensitive Areas

Steps:

  1. πŸ“ Open your nginx configuration file at /etc/nginx/nginx.conf.

  2. πŸ“ Within the server block, add a location block for the restricted area:

     server {
         listen 80;
         server_name yourdomain.com;
    
         location /restricted {
             deny all;
             return 403;
         }
    
         # ... other configuration ...
     }
    
  3. πŸ’Ύ Save the configuration file and restart nginx:

     sudo systemctl restart nginx
    
  4. 🌐 Accessing /restricted will now yield a 403 Forbidden error.

Apache vs Nginx: Melihat Perbedaannya Secara Mendalam

HAProxy - Software Load Balancing & SSL Certificates βš–οΈπŸ”

Use Case: Load Balancing and SSL Termination

Steps:

  1. πŸ“ Install HAProxy using:

     sudo apt-get install haproxy
    
  2. πŸ“ Edit your HAProxy configuration file at /etc/haproxy/haproxy.cfg.

  3. πŸ“ Configure the frontend for SSL termination:

     frontend https_frontend
         bind *:443 ssl crt /etc/haproxy/ssl/your_certificate.pem
         mode http
         option httplog
         default_backend backend_servers
    
  4. πŸ“ Define the backend servers:

     backend backend_servers
         mode http
         balance roundrobin
         server webserver1 192.168.1.10:80
         server webserver2 192.168.1.11:80
         # Add more servers as needed
    
  5. πŸ’Ύ Save the configuration and restart HAProxy:

     sudo systemctl restart haproxy
    

Apache 2 - Setting Up a Web Server πŸ› οΈ

Use Case: Basic Web Hosting

Steps:

  1. πŸ“ Install Apache 2 with:

     sudo apt-get install apache2
    
  2. πŸ“ Place your website files in /var/www/html.

  3. πŸ“ Create a virtual host configuration:

     sudo nano /etc/apache2/sites-available/your_site.conf
    
     <VirtualHost *:80>
         ServerName yourdomain.com
         DocumentRoot /var/www/html/your_site
         # Other configuration directives
     </VirtualHost>
    
  4. πŸ“ Enable the virtual host and necessary modules:

     sudo a2ensite your_site.conf
     sudo a2enmod rewrite
    
  5. πŸ“ For SSL, use Let's Encrypt certificates with certbot:

     sudo apt-get install certbot python3-certbot-apache
     sudo certbot --apache
    
  6. πŸ’Ύ Restart Apache:

     sudo systemctl restart apache2
    

Choose the Right Web Server for Your Needs! πŸ›‘οΈ

πŸ“ Conclusion:

Each web server discussed above has its strengths, making them suitable for different scenarios. Nginx excels at access control, HAProxy shines as a load balancer and SSL terminator, and Apache 2 offers a robust foundation for general web hosting. Tailor your choice to your project's unique requirements and enjoy a seamlessly running web application. πŸš€πŸŒ.

πŸ” Checkout GitHub Repository for projects:

πŸ”— https://linktr.ee/sumanprasad007

πŸ” Check out my YouTube channel - Prasad Suman Mohan:

πŸ”— youtube.com/@sumanprasad007

Did you find this article valuable?

Support Prasad Suman Mohan by becoming a sponsor. Any amount is appreciated!

Β