Quantcast

Nginx Nodejs Raspberry Pi2 Bad Gateway

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Nginx Nodejs Raspberry Pi2 Bad Gateway

fengx
This is what my setup looks like:

INTERNET (subdomain.domain.com A Record to public IP 186....187)
Hurl.it -----POST-----> Public IP:
https://186....187/API/switches?sw1?password=123456 -----> Linksys Router
IP:186...187:443 Port Forward to 192...53

ONLAN (nginx setup https with ssl from letsencrypt)
192....53 RPi2 nginx config bypass 192...53:442 . ------> nodejs app.js
listening on port 442

This is my nginx config file:

[code]
server {
        listen 443 ssl;
        listen [::]:443 ssl;
        server_name subdomain.domain.com;

        ssl_certificate        
/etc/letsencrypt/live/subdomain.domain.com/fullchain.pem;
        ssl_certificate_key    
/etc/letsencrypt/live/subdomain.domain.com/privkey.pem;

        root /www/subdomain.domain.com/aism;
        index index.php index.html index.htm;

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        # Error & Access logs
        error_log /www/subdomain.domain.com/logs/error.log error;
        access_log /www/subdomain.domain.com/logs/access.log;

        location / {
                index index.html index.php;
                proxy_pass <a href="http://192.168.1.53:442;">http://192.168.1.53:442;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }
        location ~ /.well-known {
                allow all;
        }
        location /public {
                root /www/subdomain.domain.com/aism;
        }
        location ~
^/(images/|img/|javascript/|js/|css/|stylesheets/|flash/|media/|static/) {
        }
}[/code]

I have tested the nodejs app while on port 80 from hurl.it with the port
forward config for port 80 instead and it works perfectly.

Here is the current error log:

[quote]
OST /API/switches/sw1?password=123456 HTTP/1.1", upstream:
"http://192.168.1.53:442/50x.html", host: "subdomain.domain.com"
2017/04/23 20:08:38 [error] 20424#0: *4 upstream prematurely closed
connection while reading response header from upstream, client:
192.168.1.56, server: subdomain.domain.com, request: "GET /aism/ HTTP/1.1",
upstream: "http://192.168.1.53:442/aism/", host: "subdomain.domain.com"
2017/04/23 20:08:38 [error] 20424#0: *4 upstream prematurely closed
connection while reading response header from upstream, client:
192.168.1.56, server: subdomain.domain.com, request: "GET /aism/ HTTP/1.1",
upstream: "http://192.168.1.53:442/50x.html", host: "subdomain.domain.com"
2017/04/23 20:09:25 [error] 20467#0: *1 upstream prematurely closed
connection while reading response header from upstream, client:
23.20.198.108, server: subdomain.domain.com, request: "POST
/API/switches/sw1?password=123456 HTTP/1.1", upstream:
"http://192.168.1.53:442/API/switches/sw1?password=123456", host:
"subdomain.domain.com"
[/code]

Please help!

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,273837,273837#msg-273837

_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Nginx Nodejs Raspberry Pi2 Bad Gateway

Francis Daly
On Tue, Apr 25, 2017 at 10:13:19AM -0400, marciokoko wrote:

Hi there,

I confess that it's a bit confusing to me what exactly you are doing here.

Can you create one "curl" command which makes one request, that gives
a response that is not what you want to see?

If you can show what you expect to see instead, that might be helpful too.

If at all possible, copy-paste the pieces you are reporting, rather than
re-typing things.

It looks like there may be some typographical errors in what you report
here, which might be what is unclear to me.

> INTERNET (subdomain.domain.com A Record to public IP 186....187)
> Hurl.it -----POST-----> Public IP:
> https://186....187/API/switches?sw1?password=123456 -----> Linksys Router
> IP:186...187:443 Port Forward to 192...53
>
> ONLAN (nginx setup https with ssl from letsencrypt)
> 192....53 RPi2 nginx config bypass 192...53:442 . ------> nodejs app.js
> listening on port 442

I *think* that the intention here is that a https request gets to nginx,
and then nginx makes a http request to the port-442 listener.

Can you show the request that gets to nginx, and the request that gets
to port 442, and see what the port-442 listener does with it?

>         error_page 404 /404.html;
>         error_page 500 502 503 504 /50x.html;

Unless you have a location{} that matches those html urls, they may be
proxy_pass'ed to port 442 as well, which may make it more difficult than
necessary to interpret the log files.

> 2017/04/23 20:08:38 [error] 20424#0: *4 upstream prematurely closed
> connection while reading response header from upstream, client:
> 192.168.1.56, server: subdomain.domain.com, request: "GET /aism/ HTTP/1.1",
> upstream: "http://192.168.1.53:442/aism/", host: "subdomain.domain.com"

"upstream prematurely closed connection" suggests that nginx thinks that
the port 442 listener did something wrong. Are there logs of what the
port 442 listener thinks happened?

Good luck with it,

        f
--
Francis Daly        [hidden email]
_______________________________________________
nginx mailing list
[hidden email]
http://mailman.nginx.org/mailman/listinfo/nginx
Loading...