Deploy React with Nginx failed to load resources
Please check this https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/
You have to specify the way static files are to served depending upon the url requested for static files.
Hope it helps!
try using this config to build the docker
# build environmentFROM node:9.6.1 as builderRUN mkdir /usr/src/appWORKDIR /usr/src/appENV PATH /usr/src/app/node_modules/.bin:$PATHCOPY package.json /usr/src/app/package.jsonRUN npm install --silentRUN npm install react-scripts@1.1.1 -g --silentCOPY . /usr/src/appRUN npm run build# production environmentFROM nginx:1.13.9-alpineCOPY --from=builder /usr/src/app/build /usr/share/nginx/htmlEXPOSE 80CMD ["nginx", "-g", "daemon off;"]
never had any problem using this script. U might miss some nginx config or forgot to copy recursively, who knows if u didnt post the Dockerfile
*note: i didnt make it
credit: https://mherman.org/blog/dockerizing-a-react-app/
I think this is an elegant solution for nginx reverse proxy cofiguration.
/etc/nginx/sites-available/app2.conf
server { listen 80; listen [::]:80; server_name example.com www.example.com; location / { proxy_pass http://localhost:3001; # recommended settings 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; }}
Don't forget symbolic link:
sudo ln -s /etc/nginx/sites-available/app2.conf /etc/nginx/sites-enabled/