score:2
First you need to specify proxy pass directive for your api calls - I would propose to add /api
in your fetch calls. Than provide upstream using the same name for your backend service as specified in docker-compose.yml. It is important that backend service proceed the web service in docker-compose.yml, otherwise you would get connection error in nginx like this nginx: [emerg] host not found in upstream "backend:8080"
You can update your nginx.conf as follows:
upstream backend {
server backend:8080;
}
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://backend;
}
include /etc/nginx/extra-conf.d/*.conf;
}
Or simply in your case provide a proxy pass to localhost as follows:
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
}
location /api {
rewrite /api/(.*) /$1 break;
proxy_pass http://localhost:8080;
}
include /etc/nginx/extra-conf.d/*.conf;
}
score:0
Sample Docker file, Included the Production build in the docker file
FROM node:15.6.0-alpine3.10 as react-build
# install and cache app dependencies
COPY package.json package-lock.json ./
RUN npm install && mkdir /react-frontend && mv ./node_modules ./react-frontend
WORKDIR /app/client/
COPY . .
RUN npm run build
# ------------------------------------------------------
# Production Build
# ------------------------------------------------------
FROM nginx:1.16.0-alpine
COPY --from=builder /react-frontend/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
To add nginx
as a server to our app we need to create a nginx.conf
in the project root folder. Below is the sample file
server {
listen 80;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Source: stackoverflow.com
Related Query
- Connect React App served on dockerized Nginx to Express server
- how to share environment variables between react app and express js server hosting it as static site
- How do I configure my Nginx server to work with a React app in a subfolder?
- Navigate a React App link to Express server dynamically
- Hot reloading in a React app with express server
- How to conect docker nginx with express and react app on windows
- Deploying React (3000) and Express (8000) app on the apache server
- Can I serve a create react app from an express server without running 'npm run build'?
- Unable to connect to api server of react js app using kubernetes?
- Zip File Download via Axios from Express Server not working in React App
- React front-end app on nginx server cannot reach the nodejs back-end
- CORs error AFTER deploying React App and separate Node API to production Unbuntu server where React static files are servered with NGINX
- React app served with express and helmet cannot make API requests
- Deploying a React + NodeJS + Express + MySQL App to Heroku only deploying the Server Not the React
- Consistent url routing on client side React app served from Express
- CORS policy: The 'Access-Control-Allow-Origin' problem when deployed NextJS app on Nginx server tries GET request to local Express server
- Create React App proxy to express server for PassportJS not working
- Serve React app via custom Express server while keeping automatic updates during development
- How to get a response from express server about an error using axios in react app
- Stop statically served React app from calling server path
- I create a build of my react app and connected with electron.js. now how to connect my backend from server folder with electron
- Nginx 500 Interal Server Error with React app - 1 rewrite or internal redirection cycle while internally redirecting to "/index.html"
- Create react app served with nginx and oauth gives me refresh page issue
- Having issues displaying react app on nginx server at domain
- React app - unable to connect to SQL Server database
- Express server doesn't respond correctly when hosted in a remote server, as I am using React Redux locally to get data of Express app remotely
- Can't connect to frontend in Dockerized React web app on MacOS
- How to send requests to a nodejs backend from a React app served by nginx with ssl configured
- How to get data from backend express server to frontend react app and vice versa
- React app running in docker container being served with nginx is blank
More Query from same tag
- Dropdown select component state one step behind
- When i am trying to call the api using thunk , i am getting undefined
- React Redux how to use one reducer for two similar actions in two different components?
- Redux - Error: Invalid value of type object for mergeProps
- "Cannot read property 'map' of undefined" when utilizing .map to create various JSX components?
- setFieldsValue does not re-render form value
- Wepack error : Adjacent JSX elements must be wrapped in an enclosing tag
- What is the best way to use a different API URL in production for a create-react-app using docker?
- material-ui-popup-state change button color
- Uncaught Error: Cannot find module "react"
- How can I redirect facebook crawler bot to another webpage?
- Why is this handleBlur function with event parameters when the event parameter is not used inside the function?
- How to render PDF in Gatsby JS?
- Why can we update a value of a number input using mouse wheel?
- react-native camera roll "null is not an object (evaluating 'this.state.photos')"
- React function component setTimeout - Multiple render calls and rerenders (recommended approach) (fires multiple times)
- How to reset data in UseEffect React Hooks before each rendering?
- react js getting data from a input field
- ReCaptcha v3 always has a score of 0.1 points. In chrome secret mode
- Find by key and replace the value in an object
- How to deal with the props and tightly coupled components in React?
- Cannot use token from localstorage in React
- how can i use Google maps with primereact
- How to use a same DB with 2 different React applications
- How to get the value of input in Material-UI
- How to add conditional styleclass to React AsyncTypeahead
- Rendered more hooks than during the previous render in NextJS using GraphQL
- Nextjs Nested Dynamic route
- path is required in mongoose
- NodeJs express, not caching images