Welcome! Log In Create A New Profile

Advanced

Nginx and Nodejs app on RPi2 - Routing issues

Posted by marciokoko 
Nginx and Nodejs app on RPi2 - Routing issues
April 23, 2017 08:39PM
I originally configured the nodejs app on the rpi2 behind a linksys router and the app responded fine from an outside server.

Then I installed nginx and added https with a certificate from letsencrypt and it served the https site just fine to my Mac on the same network.

Now that I'm trying to combine the two, but it's not working, I get a 404 not found. My app is at:

/www/subdomain.domain.com/aism/app.js

The nginx config for that /etc/nginx/sites-available/subdomain.domain.com is as follows:

[code]
server {
listen 80;
listen [::]:80;
server_name subdomain.domain.com;
return 301 https://$server_name$request_uri;
}

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;
index index.php index.html index.htm;

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /www/subdomain.domain.com;
}

# 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 http://LocalLanIp: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 ~ [^/].php(/|$) {
fastcgi_split_path_info ^(.+?.php)(/.*)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
[/code]



Edited 1 time(s). Last edit at 04/23/2017 08:41PM by marciokoko.
Re: Nginx and Nodejs app on RPi2 - Routing issues
April 23, 2017 09:33PM
I just checked the error log and it looks like this:

[code]
2017/04/23 19:30:48 [error] 20219#0: *1 upstream prematurely closed connection while reading response header from upstream, c$
2017/04/23 19:30:48 [error] 20219#0: *1 open() "/www/subdomain.domain.com/aism/50x.html" failed (2: No such file or directory$
[/code]
Re: Nginx and Nodejs app on RPi2 - Routing issues
April 23, 2017 10:04PM
I removed the 50x.html line in the config. Now I get this bad gateway error from hurl.it & the error log on the pi looks like this:

2017/04/23 19:48:27 [error] 20302#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"
2017/04/23 19:48:27 [error] 20302#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/50x.html", host: "subdomain.domain.com"

Thats the correct localLanIP for the rpi and the 442 port is whats configured in the .env file for the app.js to listen for.
Re: Nginx and Nodejs app on RPi2 - Routing issues
April 24, 2017 08:28PM
Here is the setup!
Attachments:
open | download - FullSizeRender (9).jpg (368.5 KB)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 160
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready