No meu Ubuntu Server 10.04, estou executando um exemplo de aplicativo node.js:
var http = require("http");
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/html"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(3000);
Ele simplesmente escuta os pedidos na porta 3000, loga no console este pedido e envia ao cliente um HTTP "Hello World"
O objetivo era tornar esse aplicativo coexistente com o Apache2. Então, depois de algumas pesquisas, editei o arquivo padrão ( / etc / apache2 / sites-available / default ) desta maneira:
<VirtualHost *:80>
ServerAdmin [email protected]
ServerName dev.myserver.com
<Location /node>
ProxyPassReverse http://127.0.0.1:3000/
ProxyPass http://127.0.0.1:3000/
</Location>
<Proxy>
Allow from all
</Proxy>
DocumentRoot /home/haj/www/http_home
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/haj/www/http_home/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /home/haj/www/log/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /home/haj/www/log/access.log combined
</VirtualHost>
Assim, quando um usuário faz uma chamada para http://dev.myserver.com/node
ou http://dev.myserver.com/node/
, o Apache faz proxy da solicitação, o Node.js faz o processamento e o usuário recebe um "Hello World".
Existe apenas um problema: Demora algum tempo, vamos chamar-lhe 'Load' the Proxy, por outras palavras, recebo estas mensagens no navegador:
<503 Service Temporarily Unavailable>
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
Apache/2.2.14 (Ubuntu) Server at dev.neosource.cl Port 80
Além disso, error.log me diz:
[Thu Apr 21 01:02:10 2011] [error] proxy: HTTP: disabled connection for (127.0.0.1)
[Thu Apr 21 01:02:10 2011] [error] proxy: HTTP: disabled connection for (127.0.0.1)
[Thu Apr 21 01:02:10 2011] [error] proxy: HTTP: disabled connection for (127.0.0.1)
Então, de repente, Funciona, assim mesmo. Sem número de pedidos, sem tempo, sem nenhum padrão.
Em termos leigos, o serviço tem que 'carregar' , essa é a impressão que dá, mas, eu gostaria de saber se existe uma maneira de minimizar esse atraso. Ou eu preferiria saber O que está errado com a configuração mencionada acima.
Editar 1 : Depois de modificar o LogLevel para depurar, durante um desses atrasos, recebo este por solicitação:
[Thu Apr 21 02:30:40 2011] [debug] mod_proxy_http.c(56): proxy: HTTP: canonicalising URL //127.0.0.1:3000/
[Thu Apr 21 02:30:40 2011] [debug] proxy_util.c(1494): [client 200.xxx.yyy.zzz] proxy: http: found worker http://127.0.0.1:3000/ for http://127.0.0.1:3000/
[Thu Apr 21 02:30:40 2011] [debug] mod_proxy.c(993): Running scheme http handler (attempt 0)
[Thu Apr 21 02:30:40 2011] [debug] mod_proxy_http.c(1940): proxy: HTTP: serving URL http://127.0.0.1:3000/
[Thu Apr 21 02:30:40 2011] [debug] proxy_util.c(1937): proxy: HTTP: retrying the worker for (127.0.0.1)
[Thu Apr 21 02:30:40 2011] [error] proxy: HTTP: disabled connection for (127.0.0.1)
[Thu Apr 21 02:30:40 2011] [debug] mod_deflate.c(615): [client 200.xxx.yyy.zzz] Zlib: Compressed 405 to 273 : URL /node
... e quando estiver certo novamente:
[Thu Apr 21 02:35:16 2011] [debug] mod_proxy_http.c(56): proxy: HTTP: canonicalising URL //127.0.0.1:3000/
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(1494): [client 200.xxx.yyy.zzz] proxy: http: found worker http://127.0.0.1:3000/ for http://127.0.0.1:3000/
[Thu Apr 21 02:35:16 2011] [debug] mod_proxy.c(993): Running scheme http handler (attempt 0)
[Thu Apr 21 02:35:16 2011] [debug] mod_proxy_http.c(1940): proxy: HTTP: serving URL http://127.0.0.1:3000/
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(1999): proxy: HTTP: has acquired connection for (127.0.0.1)
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(2055): proxy: connecting http://127.0.0.1:3000/ to 127.0.0.1:3000
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(2153): proxy: connected / to 127.0.0.1:3000
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(2244): proxy: HTTP: backend socket is disconnected.
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(2308): proxy: HTTP: fam 2 socket created to connect to 127.0.0.1
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(2414): proxy: HTTP: connection complete to 127.0.0.1:3000 (127.0.0.1)
[Thu Apr 21 02:35:16 2011] [debug] mod_proxy_http.c(1723): proxy: start body send
[Thu Apr 21 02:35:16 2011] [debug] mod_deflate.c(615): [client 200.xxx.yyy.zzz] Zlib: Compressed 11 to 13 : URL /node
[Thu Apr 21 02:35:16 2011] [debug] mod_proxy_http.c(1816): proxy: end body send
[Thu Apr 21 02:35:16 2011] [debug] proxy_util.c(2017): proxy: HTTP: has released connection for (127.0.0.1)