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
- Apache:
- Stop Web Server:
- Apache:
sudo service apache2 stop
- Nginx:
sudo service nginx stop
- Apache:
- Restart Web Server:
- Apache:
sudo service apache2 restart
- Nginx:
sudo service nginx restart
- Apache:
Configuration Files
- Apache:
- Main Configuration File:
/etc/apache2/apache2.conf
- Virtual Hosts:
/etc/apache2/sites-available/
- Main Configuration File:
- Nginx:
- Main Configuration File:
/etc/nginx/nginx.conf
- Server Blocks (Virtual Hosts):
/etc/nginx/sites-available/
- Here is a dedicated NGINX Cheat Sheet.
- Main Configuration File:
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
- Error Log:
- Nginx Logs:
- Error Log:
/var/log/nginx/error.log
- Access Log:
/var/log/nginx/access.log
- Error 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
- Enable Virtual Host:
- 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
- Create Symbolic Link:
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
andGroup
directives inapache2.conf
. - Nginx: Modify
user
directive innginx.conf
.
- Apache: Modify
- Adjust File Permissions:
sudo chown -R www-data:www-data /var/www/html
- Here is a dedicated File Permissions Cheat Sheet.
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; }
- Add to server block:
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.