DEV Community

Cover image for How To Serve Node.js Applications with Nginx on a Raspberry

How To Serve Node.js Applications with Nginx on a Raspberry

Guim on January 30, 2019

This is a tutorial of how I made my own server with Nginx to serve Node.js applications using a Raspberry Pi on my local network. I did it to have ...
Collapse
 
timmachinelogic profile image
tim-machine-logic

First, this was super helpful so thank you. I'm stuck on the following command:

iptables -A INPUT -p tcp -s localhost --dport 3000 -j ACCEPT

I get the following error:

iptables v1.8.2 (nf_tables): unknown option "--dport"

I tried going to the iptables documentation and they have similar commands like the following so not sure why the first one doesn't work:

iptables -A INPUT -p tcp -s 15.15.15.0/24 --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT

Collapse
 
jxboi profile image
Jia Xing

iptables-legacy -A INPUT -p tcp -s localhost --dport 3000 -j ACCEPT
iptables-legacy -A INPUT -p tcp --dport 3000 -j DROP

this works for me

Collapse
 
zeerorg profile image
Rishabh Gupta

You can use ufw package to block incoming traffic at a port, then you won't have to work with iptables

Collapse
 
guimg profile image
Guim

Indeed, but I'm used to doing it from the iptables software itself. 😄

Collapse
 
brandonwallace profile image
brandon_wallace

If you have a Raspberry Pi running as a web server you could set the IP address statically. It will work even if you have a DHCP server running on the network. If the DHCP server stops you will not be able to get to your web server.

Collapse
 
nahinakbar profile image
Nahin Akbar

Will this work on a VPS?

Collapse
 
guimg profile image
Guim

Sure, I have a VPS hosting for my personal website and I follow the same logic explained here (without the Raspberry of course). Worked perfectly for me.

Collapse
 
luiscarlosb3 profile image
Luis Carlos Galvão de Oliveira

I tried to load a ejs page with a public default folder and any of my css file was found, anyone have any tip for this?

Collapse
 
recurs1v0 profile image
EPPR

You need to add this on line 3

app.use(express.static('public'))

This is how you specify that a folder called "public" will serve static files.

Assuming you have a folder called "css" inside "public"
you can then access like
raspberrypi.local/css/styles.css