Apache Webserver

From wiki.linuxonlinehelp.de
Jump to: navigation, search

Redirects for Browser with .htaccess

Redirect Browser by Language to other Websites

Create a .htaccess at the Webspace and enter:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:Accept-Language} ^de [NC]
RewriteRule ^$ /linux-support-deutsch [L,R=301]
RewriteRule ^$ /linux-support-english [L,R=301]

This will redir German and International Users to two different Sites.

Block Access to Subfolders wp-includes of Wordpress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-admin/includes/ - [F,L]
RewriteRule !^wp-includes/ - [S=3]
RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]
RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]
RewriteRule ^wp-includes/theme-compat/ - [F,L]

Analyses and Diagnostics

Apache Log analyse on Console

create a bash script called apache-analyse.sh enter:

cat /var/log/apache2/access.log | awk '{ print $1 }' | sort | uniq -c
exit 0

System Echos like this:

1573  www.domain2.de
3568  www.domain3.de

Analyse Spam Bots and block them

get IP Adresses from Spambots (here xovibot) to update the Firewalls do:

sudo cat /var/log/apache2/access.log|grep xovibot.net| awk '{ print $2 }' | sort | uniq -c | sort -n > x.log

System Echos:


manual update to ufw firewall (can be done automatic too, but can take you offline for search engines if the do 404) do:

$sudo ufw insert 1 deny from to any       # insert rule
$sudo service ufw force-reload                           # force update firewall
$sudo ufw status numbered                                # test status

Load Balancer for virtual hosts with https

  • Enable apache24 proxy and ssl modules:
$sudo a2enmod proxy proxy_balancer proxy_http ssl && service apache2 restart
  • Now create at /etc/apache2/sites-available
<VirtualHost *:80>
ServerName linuxonlinehelp.de
ServerAlias www.linuxonlinehelp.de
RedirectPermanent / https://linuxonlinehelp.de/

<VirtualHost *:443>
ProxyRequests off  #MAJOR!!
ServerName linuxonlinehelp.de
ServerAlias www.linuxonlinehelp.de

ProxyPreserveHost on
ProxyPass / balancer://linuxblog:443/
ProxyPassReverse / balancer://linuxblog:443/

<Proxy *>
Require all granted

<Proxy balancer://linuxblog>
                BalancerMember https://192.168.XXX.001 
                BalancerMember https://192.168.XXX.002 
                ProxySet lbmethod=byrequests
SSLProxyEngine on
SSLEngine on
SSLCertificateFile     /etc/ssl/cert.pem
SSLCertificateKeyFile  /etc/ssl/privkey.pem
SSLCACertificateFile   /etc/ssl/fullchain.pem
  • enable the Config with:
$sudo a2ensite linuxblog.conf && service apache2 restart


  • Disable ALWAYS!! the Balance Manager for Security Reasons over apache2.conf
  • Check ALWAYS the Apache Logs for Errors! on both Balance Member Servers!!

Dump Dynamic Webpage to Static HTML Website for Embedded Webservers (Raspberry Pi without MYSQL)

Drupal Dump to tmp (tmpfs Ramdisk) for lighttpd/apache2 serving /tmp/web on FAST I/O :

cd /tmp/web
wget -q --mirror -p --adjust-extension -e robots=off --base=./ -k -P ./ https://www.my-domain.org