Virtual Hosting in Apache (Part 1)
Oct 08, 07 by Juan Lebrijo about blog, Web
If we want to publish various domains, we would not need the same number of servers as domains. With Apache Virtual Hosting we can have all domains we need in one server. Today is the firs part to deploy in practice this subject, in some days we will have the second part: Apache Virtual Hosting (Part 2). There are two virtual hosting types:
  • Name based: One IP to various domains.
  • IP based: Every domain have its IP, every IPs as network interfaces have our server.
Usually (in hme servers) we take the name-based hosting, therefore we host more than one domain, or subdomains, or host other domains and portals (I hope with payment). It happens to me, then I am going to tell you my experience in some cases and concrete applications. In Apache2 we can adminitrate virtual hosting in a directory. Then we can do so many files as hosted sites you have in the file /etc/apache2/sites-available/default.

Basic site: www

The site www.tudominio.com is a subdomain in tudominio.com, therefore this example runs for blog.tudominio.com, motos.tudominio.com,.... BE CAREFUL: Never forget type your domain in your DNS server (you can study in depth here); or throug your Domain Register if you do not have DNS server. The tag basic structure is:
<VirtualHost *>
        ServerAdmin webmaster@tudominio.com
        ServerName www.tudominio.com
        ServerAlias tudominio.com
        DocumentRoot /var/www/tudominio

        ErrorLog /var/log/apache2/error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On
</VirtualHost>
Commentin the tags one by one:
  • ServerAdmin: Web server administrator mail.
  • ServerName: What domain name petitions server must reply.
  • ServerAlias: Solve errors, as forgetful clients who forget typing www.
  • DocumentRoot: directory where I copy my published data.
  • ErrorLog: Log where the daemon type the errors. So we do not abuse of syslog.
  • LogLevel: Detail level for the errors receptioned.
  • CustomLog: Log where type your clients accessed.
  • ServerSignature: Autogenerated pages final signature; where usually appends the operating system, web server, verions, etc.

Redirection to a executable cgi out of web tree

For example we can publish the charge lever of an UPS; the manufacturer provides a cgi:
<VirtualHost *>
        ServerName sistema.tudominio.com
        DocumentRoot /var/www/tudominio/sistema

        ScriptAlias /sai/ "/usr/lib/cgi-bin/nut/"
        <Directory "/usr/lib/cgi-bin/nut">
                AllowOverride None
                Options +ExecCGI
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>
We have the the two first lines the name for the domain of the response, and the rrot directory. Really al this the estrategy is in ScriptAliastag and the Directory directive, wich be able to  be hoste in every domain:
  • ScriptAlias: Is the nick (/sai/) which will be the directory where are hosted our cgi's.
  • Directory: Only specifies how i managed a directory out of the tree.
In this way we call from our web browser to the cgi file as follows: http://sistema.tudominio.com/sai/ejecutable.cgi You can continue the second part of this subject in the link: Apache Virtual Hosting (Part 2).
Hosting Virtual en Apache (Parte I)
Oct 08, 07 by Juan Lebrijo about blog, Web, Services
Si queremos publicar varios dominios, no haría falta tener tantos servidores como dominios. Con el Virtual Hosting de Apache podríamos montar tantos dominios como quisieramos en un servidor. Hoy es la primera entrega para desarrollar de forma práctica esta temática, dentro de unos días aparecerá en este blog la segunda entrega: Hosting Virtual en Apache (Parte II). Hay dos tipos de Hosting Virtual:
  • El basado en Nombre: con una IP sirves varios dominios.
  • El basado en IP: Cada dominio puede tener su IP, tantas IP como interfaces de red tenga instalado nuestra máquina.
Lo normal (en los que a servidores caseros se refiere) es hacer el "basado en Nombre" ya que nos solemos liar y hacer más de un portal web en nuestro dominio, ó incluso alojar otros portales (espero que lo hagais previo pago). A mi me ha pasado, naturalmente, y os voy a contar mis peripecias con varios casos y aplicaciones concretas. En Apache2 los virtual hosts se administran en un directorio. De forma que podeis hacer include de tantos ficheros como sitios tengais en el archivo /etc/apache2/sites-available/default.

Sitio básico: www

El sitio www.tudominio.com es un subdominio en realidad de tudominio.com, por tanto este ejemplo sirve para blog.tudominio.com, motos.tudominio.com,.... OJO: Eso sí nunca debeis olvidar dar de alta el subdominio en vuestro Servidor DNS (podeis ver más detalladamente como aquí); ó si no teneis servidor propio hacerlo a través de vuestro registrador de dominio. La estructura básica de la etiqueta es:
<VirtualHost *>
        ServerAdmin webmaster@tudominio.com
        ServerName www.tudominio.com
        ServerAlias tudominio.com
        DocumentRoot /var/www/tudominio

        ErrorLog /var/log/apache2/error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On
</VirtualHost>
Comentando las etiquetas una a una tenemos:
  • ServerAdmin: Correo del administrador del servidor web.
  • ServerName: A que peticiones de nombre de dominio a este servidor debo responder.
  • ServerAlias: Esta etiqueta es para resolver errores, como los xlientes olvidadizos que se olvidan de poner la www.
  • DocumentRoot: el directorio donde alojemos el contenido que queremos publicar.
  • ErrorLog: El log donde queremos que apunte los fallos. Así no inundamos el general, y no se convierte en inmanejable.
  • LogLevel: El nivel de detalle de errores que queremos que recoja.
  • CustomLog: El log donde se apunta quien accede a tu sitio.
  • ServerSignature: La línea final en las páginas autogeneradas; donde se indica el sistema operativo, servidor web, versiones, etc.

Redirigir a un ejecutable cgi fuera del arbol web

Por ejemplo para publicar la páqina de carga de un sai; el software que te proporciona el fabricante es un cgi:
<VirtualHost *>
        ServerName sistema.tudominio.com
        DocumentRoot /var/www/tudominio/sistema

        ScriptAlias /sai/ "/usr/lib/cgi-bin/nut/"
        <Directory "/usr/lib/cgi-bin/nut">
                AllowOverride None
                Options +ExecCGI
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>
Tenemos en las dos primeras líneas el nombre para el dominio sobre el que se responderá al alias, y el directorio base. En realidad el grueso de esta estrategia está en la etiqueta ScriptAlias y la directiva Directory, que pueden estar en cualquier dominio planteado:
  • ScriptAlias: Dice el sobrenombre (/sai/) que va a poner al directorio donde se alojan nuestros cgi's.
  • Directory: Simplemente especifica como manejar este directorio externo al arbol.
De esta forma llamaremos desde el cliente web a nuestro cgi de la siguiente manera: http://sistema.tudominio.com/sai/ejecutable.cgi Podeis continuar con la segunda entrega de este artículo en el enlace: Hosting Virtual en Apache (Parte II).
Apache, web server installation
Oct 04, 07 by Juan Lebrijo about blog, Web
The Web is the primary system to publish contents in internet, Tim Berners-Lee thought that must to format easy and unified thmillions of texts, and invented the HTML. Apache is one of the most popular web servers (maybe the most popular). I have installed Apache2 to serve this pages, over Debian Etch, and i am gonna show how idid it. As usually apt and deb packages makes easy the basics installation tasks:
elite:~# apt-get install apache2 apache2-mpm-worker apache2-utils libexpat1
                                                 openssl ssl-cert
Leyendo lista de paquetes... Hecho
Creando árbol de dependencias... Hecho
Paquetes sugeridos:
  apache2.2-common libapr1 libaprutil1 libpq4 libsqlite3-0
Paquetes sugeridos:
  ca-certificates
Se instalarán los siguientes paquetes NUEVOS:
  apache2 apache2-mpm-worker apache2-utils apache2.2-common libapr1 libaprutil1
                                  libexpat1 libpq4 libsqlite3-0 openssl ssl-cert
0 actualizados, 8 se instalarán, 0 para eliminar y 6 no actualizados.
Necesito descargar 3451kB de archivos.
Se utilizarán 9023kB de espacio de disco adicional después de desempaquetar.
Do not forget open the port 80 to our local IP server in order to everybody see all that we publish. To remove the installation default redirection, in /etc/apache2/sites-available/default, comment the line:
#RedirectMatch ^/$ /default/
To accept the accents we must set a latin charset. Uncomment in apache2.conf:
AddDefaultCharset ISO-8859-1
If you want to extend information about apache, you have the follow table: Origin http://httpd.apache.org/ Repository http://httpd.apache.org/download.cgi Package apt 2.0.54 Documentation (Spanish) http://httpd.apache.org/docs/2.0/ Documentation (English) Files Configuration: /etc/apache2/apache2.conf Root directory: /var/www Script daemon: /etc/init.d/apache2 Log: /var/log/apache/ Ports Server: 80 TCP HTTP-SSL: 443 TCP