Akward หน่วงเวลาในการเชื่อมต่อคำขอพร็อกซีของ Apache กับแอป node.js


12

ใน 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/Apache ขอให้ผู้รับมอบฉันทะ Node.js ทำการประมวลผลและผู้ใช้จะได้รับ "Hello World" กลับมา

มีปัญหาเดียว: ใช้เวลาพอสมควรลองเรียกมันว่า 'โหลด' พร็อกซีในคำอื่น ๆ ฉันได้รับข้อความเหล่านี้ที่เบราว์เซอร์:

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

ถึงผู้ดูแล: ฉันไม่แน่ใจว่านี่เป็นคำถามของ stackoverflow หรือคำถาม serverfault ดังนั้นฉันจึงโพสต์ทั้งสองไซต์
Herman Junge

1
การโพสต์ข้ามเป็นความคิดที่ไม่ดีเว้นแต่คุณจะไม่ได้รับคำตอบจากนั้นให้แน่ใจว่าได้ทำการเชื่อมโยงระหว่างพวกเขาด้วยเช่นกัน! หากคุณโพสต์ผิดที่ผู้ดูแลจะช่วยโยกย้ายไปยังสถานที่ที่เหมาะสม แต่โปรดอย่าเพียงแค่ทำซ้ำความพยายามของเราตั้งแต่เริ่มต้น!
Caleb

ขออภัย @Caleb ความผิดพลาดของผู้เริ่มต้น จะไม่เกิดขึ้นอีก
Herman Junge

ไม่ต้องกังวลนี่คือการเรียนรู้ตามที่คุณไป
Caleb

คำตอบ:


10

การเปลี่ยนLogLevelเป็นdebugจะให้ข้อมูลเพิ่มเติมแก่คุณใน error.log กรุณาทำเช่นนั้นและโพสต์ผลลัพธ์ หากไม่มีข้อมูลดังกล่าวฉันคาดเดาได้ว่าการเปลี่ยนสาย ProxyPass ของคุณProxyPass http://127.0.0.1:3000/ retry=0อาจช่วยได้ โดยทั่วไปแล้วเอกสาร Apache mod_proxyมีรายละเอียดเพิ่มเติมเกี่ยวกับพารามิเตอร์ที่คุณสามารถใช้ได้


ขอบคุณ @justarobert ตอนนี้ฉันได้พบกับ "Inverse Murphy" เพราะฉันพยายามที่จะทำซ้ำข้อผิดพลาดและทุกอย่างเป็นไปด้วยดี! ฉันพนันได้เลยว่าในการผลิตฉันจะมีสถานการณ์นี้อีกครั้ง ... ทันทีที่ฉันมีข้อมูลฉันจะกรอกข้อมูลที่นี่ ขอบคุณอีกครั้ง.
Herman Junge

ตัวเลขนั่น! ตรวจสอบให้แน่ใจว่าจะไม่ใช้LogLevel debugในการผลิต
justarobert

ฮ่า ๆ. ฉันเพิ่งแก้ไขคำถามของฉัน
Herman Junge

1
บันทึก Apache ระบุว่ากระบวนการ node.js ของคุณไม่ตอบสนองต่อคำขอพร็อกซีในระหว่างการล่าช้า คุณได้รับอะไรจากบันทึกของ node.js ในเวลานั้น? คุณสามารถเยี่ยมชมเซิร์ฟเวอร์ node.js ในเบราว์เซอร์ของคุณโดยตรงเมื่อ Apache ให้ความล่าช้าแก่คุณหรือไม่? พิจารณาใช้ProxyPass http://127.0.0.1:3000/ retry=0 timeout=10เพียงเพื่อทำให้การหมดเวลาชัดเจน ดูการสนทนาที่news.ycombinator.com/item?id=2037328ด้วยเหตุผลที่คุณอาจไม่ต้องการให้ Apache วางไว้หน้า node.js
justarobert

2

ขุดขึ้นมา ฉันมีปัญหานี้ใน CentOS ที่เปิดใช้งาน SELinux สิ่งที่ฉันต้องทำคืออนุญาตให้ httpd ทำการเชื่อมต่อเครือข่าย:

/usr/sbin/setsebool httpd_can_network_connect 1

(และเริ่ม httpd ใหม่)

โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.