I'm trying to configure React app for local developing, i want it to work with Nginx, but it only works when i host build folder, so live reload can't fetch any changes outside of it, and i get 500 Response when trying to host another folder in nginx. Ideally i want react with live reload working through nginx. How can i do it?
Is it possible to do it with two different containers for local development?
Dockerfile Frontend
FROM node:14
WORKDIR /var/www/static
ENV PATH /var/www/static/node_modules/.bin:$PATH
COPY ./package.json ./package-lock.json /var/www/static/
RUN npm install
COPY . /var/www/static/
Dockerfile Nginx
FROM nginx:1.11
WORKDIR /var/www/static
ADD ./frontend/build /var/www/static
Nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
gzip on;
gzip_types text/css image/png image/jpg application/json application/javascript application/xml application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost:7000;
client_max_body_size 512m;
root /var/www/static/build;
location / {
# try_files $uri $uri/ =404;
try_files $uri /index.html;
# $uri/index.html @backend;
}
location ~ ^/private-files/(.*)$ {
internal;
resolver 127.0.0.11 ipv6=off;
set $storage http://storage-proxy;
proxy_pass $storage/$1;
}
location /local-private-files/ {
internal;
alias /;
}
location /api/v4 {
# rewrite ^/api/v4/(.*)$ /$1 break;
proxy_pass http://backend_drf;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_read_timeout 3600;
}
location /redirect {
rewrite ^/(.*)$ http://$arg_go? permanent;
}
}
upstream backend_drf {
server drf:8081;
}
}
Docker and Frontend in Docker-compose
nginx:
build:
context: .
dockerfile: backend/Dockerfile.nginx
image: hub.eis24.me/nginx:1.11
env_file:
- ./backend/.env
volumes:
- "./deploy/nginx.conf:/etc/nginx/nginx.conf"
- "./frontend:/var/www/static:rw"
ports:
- "0.0.0.0:7000:80"
links:
- drf
depends_on:
- drf
- frontend
frontend:
image: hub.eis24.me/frontend:latest
build: ./frontend
volumes:
- "./frontend:/var/www/static:rw"
# ports:
# - "7000:3000"
# - "7001:6006"
environment:
- CHOKIDAR_USEPOLLING=true
command: npm start