Deploying a App (Docker +Nodejs + React + Nginx) on a Nginx Server (Raspberry Pi 3+)

Hello, I've been stuck trying to figure out how to serve up a nodejs api via nginx on my Raspberry pi 3+. I understand the hardware limitation and would probably upgrade here soon to a RPI 4. I want a nice and clean to design and implement backend api's compatible with nodejs with a nice frontend UI like Reactjs. Eventually, I will create widgets of sort with languages like python and such but I will serve them in a central React

Here is a my Dockerfile

Dockerfile:

# Stage 0: Build react image
# pull official base image
FROM node:14.10.1-alpine3.11 as build

# set working directory
WORKDIR /app

# add app
COPY . .

# start app
CMD ["npm", "start"]

# Stage 1: Setup nginx http server
FROM nginx:1.15

COPY --from=build /app/helloworld /usr/share/nginx.html

# Copy the default nginx.conf provided by tiangolo/node-frontend
COPY --from=build /nginx.conf /etc/nginx/conf.d

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]

My App is the canonical React app Hello-world. When I curl the ip address of the rpi with http, I get the nginx default page. I can curl w/ http from a different computer on the same wlan as the rpi 3+ the React app. Here is the nginx.conf copied from inside the container.

nginx.conf:

server {

listen 80;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /app/hello-world/publix/index.html;
}

error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}

Any help would be appreciated.

1 thought on “Deploying a App (Docker +Nodejs + React + Nginx) on a Nginx Server (Raspberry Pi 3+)”

  1. I am not sure what your question is. Does the react app work? Does app work but when you use curl you are getting an unexpected response.
    I have created a nodejs express app. My guess is it should be the same as a react app. The server block in nginx is. location /myapp/ { root /applocation/; proxy_pass 127.0.0.1:6060 }
    I have a service file that starts the app
    WorkingDirectory=/applocation
    ExecStart=/usr/bin/nodejs /applocation/app.js

    Start the app and it should work.

    Reply

Leave a Comment