I'm trying to serve some static content produced by running npm run build with create-react-app. Here's my nginx default.conf file:
server { listen 3000; location / { root usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; } } Here's my Dockerfile:
FROM node:14-slim as builder WORKDIR "/app" COPY ./package.json ./ RUN npm install COPY . . RUN npm run build FROM nginx EXPOSE 3000 COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf COPY --from=builder /app/build /usr/share/nginx/html If I look inside my Docker container, I can see the files are all where they should be: https://i.sstatic.net/H4hy7.png
Also for context, I'm also using nginx for routing, with this config:
upstream client { server client:3000; } upstream api { server api:3001; } server { listen 81; location / { proxy_pass http://client; } location /api { rewrite /api/(.*) /$1 break; proxy_pass http://api; } location /sockjs-node { proxy_pass http://client; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; } } However, if I try to navigate to localhost:81, I get this error:
client_1 | 2021/02/18 15:46:35 [error] 28#28: *10 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 172.18.0.3, server: , request: "GET / HTTP/1.0", host: "client" Any ideas what the issue could be? Most other threads I've looked at focus on this bit, but I already have it and I'm sure the file locations are all correct.:
server { listen 3000; location / { root usr/share/nginx/html; index index.html index.htm; try_files $uri $uri/ /index.html; <-- this line here } } Another thread suggested adding "homepage": "./" to the package.json file, but this didn't seem to make any difference either.