簡體   English   中英

nginx + node.js =通過iframely連接到上游時失敗

[英]nginx + node.js = failed while connecting to upstream with iframely

我嘗試使用Iframely。 我在服務器ubuntu + nginx上安裝了自托管版本: https : //iframely.com/docs/host

當我像這樣啟動節點時: # node server Iframely運作良好否則,我收到502錯誤的網關錯誤。

錯誤

在日志錯誤中:

2016/01/25 06:06:58 [error] 13265#0: *4476 connect() failed (111: Connection refused) while connecting to upstream, client: xx:xx:xx:xx:xx:xx, server: iframely.custom.com, request: "GET /iframely?url=http://coub.com/view/2pc24rpb HTTP/1.1", upstream: "http://127.0.0.1:8061/iframely?url=http://coub.com/view/2pc24rpb", host: "iframely.custom.com"

當我嘗試時: # curl -i 127.0.0.1:8061/iframely?url=http://coub.com/view/2pc24rpb

它確認錯誤: curl: (7) Failed to connect to 127.0.0.1 port 8061: Connection refused

我從node開始,我了解也許node.js沒有監聽8061端口。

當我嘗試時: netstat -pantu

我沒有看到有問題的端口,但其他類似的端口卻被另一個完美運行的node.js應用程序使用:

tcp6 0 0 127.0.0.1:4567 127.0.0.1:60724 ESTABLISHED 12329/node

組態

我的主機配置:

upstream iframely.custom.com {
        ip_hash;
        server localhost:8061;
        keepalive 8;
}
server {

        listen 80;
        listen [::]:80;
        server_name iframely.custom.com;
        root /usr/share/nginx/html/iframely.custom.com;

        # Logs
        access_log /var/log/iframely.access_log;
        error_log /var/log/iframely.error_log;

        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-NginX-Proxy true;

                proxy_pass http://iframely.custom.com/;
                proxy_redirect off;

                # Socket.IO Support
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }

        # Exclude from the logs to avoid bloating when it's not available
        include drop.conf;

}

我嘗試更改127.0.0.1的配置localhost,但它沒有任何更改。

如何使Node.js應用程序保持活動狀態:我是否需要永遠重啟它? ipv4或ipv6可能有問題嗎?

我將這個問題發布在serverfault上,因為我認為這是nginx配置的問題。 但是有人建議我錯了。

預先感謝您的任何幫助。 b

首先,您應該使節點應用程序監聽8061端口,並在“ netstat -tpln”中顯示它,例如:

tcp        0      0 127.0.0.1:8061          0.0.0.0:*               LISTEN      21151/node

其次,您應該使用卷曲測試。 如果做出響應,則節點服務器可以正常工作。

最后,將焦點轉移到nginx。

僅具有一個后端,使用upstream模塊沒有任何好處。 您可以像這樣刪除upstream部分並更新您的proxy_pass行:

    proxy_pass http://127.0.0.1:8061/;

后端也可能正在偵聽IP,但未響應名稱“ localhost”。 這不太可能,但有可能。 但是它必須在偵聽某些IP地址,因此使用IP地址更為安全。

弗拉迪斯拉夫的上述建議也很好。

我使用永遠解決問題: https : //github.com/foreverjs/forever

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM