Web Server Cheat Sheet

Here’s a cheat sheet for web server-related tasks and commands:

Basic Commands

  • Start Web Server:
    • Apache: sudo service apache2 start
    • Nginx: sudo service nginx start
  • Stop Web Server:
    • Apache: sudo service apache2 stop
    • Nginx: sudo service nginx stop
  • Restart Web Server:
    • Apache: sudo service apache2 restart
    • Nginx: sudo service nginx restart

Configuration Files

  • Apache:
    • Main Configuration File: /etc/apache2/apache2.conf
    • Virtual Hosts: /etc/apache2/sites-available/
  • Nginx:
    • Main Configuration File: /etc/nginx/nginx.conf
    • Server Blocks (Virtual Hosts): /etc/nginx/sites-available/
    • Here is a dedicated NGINX Cheat Sheet.

Server Status

  • Check Apache Status:
    • sudo service apache2 status
  • Check Nginx Status:
    • sudo service nginx status

Log Files

  • Apache Logs:
    • Error Log: /var/log/apache2/error.log
    • Access Log: /var/log/apache2/access.log
  • Nginx Logs:
    • Error Log: /var/log/nginx/error.log
    • Access Log: /var/log/nginx/access.log

Server Configuration Test

  • Test Apache Configuration:
    • sudo apache2ctl configtest
  • Test Nginx Configuration:
    • sudo nginx -t

Virtual Hosts

  • Apache:
    • Enable Virtual Host: sudo a2ensite your_site.conf
    • Disable Virtual Host: sudo a2dissite your_site.conf
  • Nginx:
    • Create Symbolic Link: sudo ln -s /etc/nginx/sites-available/your_site /etc/nginx/sites-enabled/
    • Remove Symbolic Link: sudo rm /etc/nginx/sites-enabled/your_site

SSL/TLS Certificates

  • Generate Self-Signed Certificate:
    • sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/private.key -out /etc/nginx/ssl/public.crt
  • Here is a dedicated SSL Cheat Sheet.

Server Modules:

  • Enable Apache Modules:
    • sudo a2enmod your_module
  • Disable Apache Modules:
    • sudo a2dismod your_module
  • Enable Nginx Modules:
    • Included in the configuration file.

User and Permissions

  • Change Web Server User:
    • Apache: Modify User and Group directives in apache2.conf.
    • Nginx: Modify user directive in nginx.conf.
  • Adjust File Permissions:

Server Security

  • Firewall Rules (UFW):
    • sudo ufw allow 80 (HTTP)
    • sudo ufw allow 443 (HTTPS)
  • Deny Access to a Directory (Nginx):
    • Add to server block: location /your_directory { deny all; }

This cheat sheet provides basic commands and configurations for Apache and Nginx web servers on a Linux system. Adjust paths and commands based on your specific server setup and distribution.