Apache의 프록시 요청을 node.js 앱에 연결하기위한 Akward 지연

내 Ubuntu Server 10.04에서 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);

포트 3000의 요청을 듣고 콘솔에 로그인하여 클라이언트에게 HTTP “Hello World”를 보냅니다.

이 앱을 Apache2와 공존시키는 것이 목표였습니다. 그래서 몇 가지 연구를 한 후 기본 파일 ( / etc / apache2 / sites-available / default )을 다음과 같이 편집했습니다 .

<VirtualHost *:80>
        ServerAdmin haj@myserver.com
        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>

사용자가 호출 할 때, http://dev.myserver.com/node또는 http://dev.myserver.com/node/아파치가 요청을 프록시, Node.js를이 처리를 만들고, 사용자가 다시 “안녕하세요”가져옵니다.

한가지 문제가있다 : 시간이 걸린다. 프록시를 ‘로드’라고하자. 즉, 브라우저에서 다음과 같은 메시지를 받는다.

<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

게다가 error.log는 다음을 알려줍니다.

[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)

그런 다음 갑자기 작동합니다. 요청 횟수, 시간 및 패턴이 전혀 없습니다.

평신도의 관점에서 볼 때 서비스는 ‘로드’ 해야합니다. 그것이 제공하는 인상이지만,이 지연을 최소화하는 방법이 있는지 알고 싶습니다. 또는 위에서 언급 한 구성의 문제점을 알고 싶습니다 .

편집 1 : LogLevel을 디버깅하도록 수정 한 후 이러한 지연 중 하나가 요청 당 발생합니다.

[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

… 그리고 다시 맞을 때 :

[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)


답변

변경 LogLevel하려면 debug당신에게하는 error.log에서 더 많은 정보를 제공합니다. 그렇게하고 결과를 게시하십시오. 그 정보가 없으면 ProxyPass 줄을 변경하면 ProxyPass http://127.0.0.1:3000/ retry=0도움 이 될 것입니다. 일반적으로 Apache mod_proxy 문서 에는 사용 가능한 매개 변수에 대한 자세한 내용이 있습니다.


답변

이것을 파고. SELinux를 사용하는 CentOS 에서이 문제가 발생했습니다. 내가해야 할 일은 httpd가 네트워크 연결을하도록 허용하는 것입니다.


/usr/sbin/setsebool httpd_can_network_connect 1

(그리고 httpd를 다시 시작하십시오)