Installer Plone 3 derrière Varnish avec Buildout

by sylvain

3 11 2008
Ce tutorial présente la marche à suivre pour déployer le CMS Plone 3 avec Buildout (Apache -> Varnish -> Zope -> Plone), le tout dans un environnement virtuel Python (VirtualEnv).


Forcing HTTP/1.0 Apache response when PHP is there…

by regilero

29 08 2008
forcing-http10-apache-response-when-php-is-there

Recently I had to force an HTTP/1.0 response with Apache because of a bad Java Parser.

This parser/browser was asking for HTTP/1.1 responses but did’nt understood chunked content encoding. And so giving me a nice Sax exception “content not allowed in prolog”. So, well, I won’t fix this #$*%! code. Better trying to talk to this special User Agent in HTTP/1.0, he might handle it in a better way. Here’s what a chunked content looks like. See the 306c hexa lenght code before the body of the response?

HTTP/1.1 207 Multi-Status
(... lot of headers, but no lenght one ...)
Content-Type: text/xml; charset="utf-8"

306c
<?xml version="1.0" encoding="utf-8"?>
(... here the content ...)

So I have the user agent of this Java HTTP Client, let’s call it ‘NoobieJavaParser’.

I simply wrote in my apache virtualhost config file:

BrowserMatch "^NoobieJavaParser" nokeepalive force-response-1.0 downgrade-1.0

And it should be sufficient. In fact it’s not because of a very old PHP bug (saw first bug report in 2004).

PHP is building is $_SERVER variable by reading Apache env, and PHP doesn’t want any dot in this parsed content. The ‘downgrade-1.0‘ env name seem malicious for PHP. So the env setting looks like that in PHP:

echo $_SERVER['downgrade-1_0'];
-> 1

See the dots is now a ‘_’. It should not hurt anyone, except PHP changed this env name in Apache as well. So when apache is sending the response, he does not care anymore about this downgrade-1_0 settings.

If you want Apache to have the real behaviour, i.e: sending HTTP/1.0 responses for this ‘NoobieJavaParser’ User Agent you must re-set the env of Apache in PHP, with something like that:

if ($_SERVER['downgrade-1_0']){
        apache_setenv(’downgrade-1.0′,’true’);
}
if ($_SERVER['force-response-1_0']){
        apache_setenv(’force-response-1.0′,’true’);
}

Ugly, but it’s PHP’s fault. and no more chunked content after that. And the nice thing is that apache_setenv is not changing $_SERVER, so PHP still does not have this malicious dot.



Some basic things about Apache VirtualHosts

by pounard

29 08 2008

For people who thinks that setup an Apache is easy (and of course, with some experience behind me, I agree), I say, beware of some details.
For those who need real technical documentation on Apache, this is not for you, this article intends to help people who only tries to setup small development or personal web servers (this do not applies on complex environments or needs).

Yesterday, I had to setup a development environment for a colleague, and it took some hours just because of theses:

read more



Temps de réponse réél d’une page web avec … netcat

by regilero

25 05 2008
temps-de-reponse-reel-dune-page-web-avec-netcat

Bon, j’imagine que la plupart des gens (heu.. d’un certain type) savent qu’on peut faire du web ‘à la main’ avec telnet ou netcat. Et bien on peut. Donc. Je voulais me servir de cela pour tracer quelques temps de réponse de pages html précises. Le tout en une seule ligne histoire de se servir de l’historique et pas de mon cerveau pour la retaper.

Commencons par un telnet sur www.google.com sur le port 80 (web). On tape la requète comme si nous étions un navigateur web (très basique le navigateur). La requète HTTP va donc être:
GET / HTTP/1.0
Remarquez qu’il y a une ligne vide (donc deux fois entrée).
Cela donne en résultat une page de redirection vers le site français de google, parfait.
nii:~$ telnet www.google.com 80
Trying 209.85.129.147...
Connected to www.l.google.com.
Escape character is '^]'.
GET / HTTP/1.0
.
HTTP/1.0 302 Found
Location: http://www.google.fr/
(.. je vous passe le reste ...)
Connection closed by foreign host.
nii:~$

Bon, maintenant je veux mesurer le temps de réponse. Avec tout bètement la commande ‘time’. Pour faire cela l’idéal est de taper ma commande en une seule fois, et là telnet n’est plus très souple pour automatiser la saisie utilisateur On va commencer par tester la même chose avec netcat (nc)
nii:~$ printf 'GET / HTTP/1.0\n\n' | \
nc -w 10 www.exemple.com 80

On avance. Par contre on a de fortes chances de ne pas tomber sur la page web que l’on recherche vraiment. On a de très fortes chances de tomber sur le VirtualHost par défaut du serveur HTTP à l’autre bout. Mais pour servir le bon site il faut taper du HTTP/1.1 au lieu de 1.0 et ajouter un header à notre requète indiquant au serveur le nom du site que l’on veut (parmi ceux qu’il héberge), revoyez le protocole http version 1.1 si vous ne comprenez rien à ce que je dis.
nii:~$ printf 'GET / HTTP/1.1\nHost:www.exemple.com\n\n' | \
nc -w 10 -q 10 www.exemple.com 80

Et maintenant pour avoir le temps de la commande je rajoute time au début et je fais sauter le temps d’affichage de la réponse…
nii:~$ time printf 'GET / HTTP/1.1\nHost:www.exemple.com\n\n' | \
nc -w 10 -q 10 www.exemple.com 80 1>/dev/null
.
real 0m0.627s
user 0m0.000s
sys 0m0.004s

Mais…
Il y a une grosse erreur. On se prends le temps d’une requète DNS de la machine sur laquelle on est qui cherche l’adresse IP de l’hôte que l’on a donné à netcat (après le nc -w 10) pour aller ouvrir une connexion tcp sur le port 80 de cet hôte. Ce temps DNS ne sert à rien, il fausse notre résultat (et c’est souvent très long le DNS). Il faut utiliser l’adresse IP du serveur web directement. De toutes façons c’est à l’intérieur du protocole HTTP, avec notre entête Host: que l’on indique le site web demandé au serveur, et pas du tout avec le nom DNS utilisé pour résoudre l’adresse IP du serveur web.
nii:~$ nslookup ww.exemple.com
66.116.125.121
nii:~$ time printf 'GET / HTTP/1.1\nHost:www.exemple.com\n\n' | \
nc -w 10 -q 10 66.116.125.121 80 1>/dev/null
.
real 0m0.408s
user 0m0.004s
sys 0m0.000s

0.408s est déjà plus proche du temps de réponse réèl du site (depuis le point du réseau où on se trouve, il y a des pertes dues au réseau, forcément).

PS: vive les sites Best Viewed with telnet to port 80



Apache Virtualhost generator

by alf

2 04 2008

Currently I’ve not much time to work on Wisss :-( However, I will make a tiny dsl and generator to have a virtualhost file generated (independent from Wisss, which already generate a vhost). I’ve already done this with a shell script but it will be more powerful and easy to maintain for a few hours of work.

The initial need is for my own server but it will also be useful for my company. The goal is to provide our best practice for vhost in a tool.