score:4
Accepted answer
- You can build React app and serve its static files with Nginx
- You can use docker-compose to manage Nginx and Django. What is more, you can build React static files during docker build.
Here is my article: Docker-Compose for Django and React with Nginx reverse-proxy and Let's encrypt certificate.
Below my Nginx configuration:
server {
listen 80;
server_name _;
server_tokens off;
client_max_body_size 20M;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api {
try_files $uri @proxy_api;
}
location /admin {
try_files $uri @proxy_api;
}
location @proxy_api {
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Url-Scheme $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://backend:8000;
}
location /django_static/ {
autoindex on;
alias /app/backend/server/django_static/;
}
}
Nginx dockerfile:
# The first stage
# Build React static files
FROM node:13.12.0-alpine as build
WORKDIR /app/frontend
COPY ./frontend/package.json ./
COPY ./frontend/package-lock.json ./
RUN npm ci --silent
COPY ./frontend/ ./
RUN npm run build
# The second stage
# Copy React static files and start nginx
FROM nginx:stable-alpine
COPY --from=build /app/frontend/build /usr/share/nginx/html
CMD ["nginx", "-g", "daemon off;"]
Source: stackoverflow.com
Related Query
- Deploy both django and react on cloud using nginx
- deploy React and Django with Nginx and Docker
- How to Deploy Django Rest Framework and React on AWS
- Authorize Spotify using React and Nginx in Docker
- Trying to deploy my REACT Webpack app to heroku. Everything works locally and the heroku build works. But I'm getting a 404 nginx
- How to upload image to aws s3 using react and django rest framework
- Django/React App: How to have both Django URLS (for the api to send data) and React URLS (to render my components) in my web app, compatibly
- Passing both match param and props into react component when using routing
- I have a question about Cloud Firestore V9 and using React Js. In one of my docs, there is a map. How do I access this map?
- react + django deploy in heroku and image isn't coming through
- Is using both Inheritance and Composition a good practice in React Class Components?
- How to set both linear-gradient and background image in a specific div using styles in React
- I want to navigate to a page/component where I passed the data from another component using both React hooks and useHistory, but I get undefined
- How to implement pagination in a Django and React app without using the REST framework?
- How to fix 500 internal server error while using Django and React
- Best way to proceed to have both public and private routes on a single web app using Keycloak and React router?
- how to pass pk using django and react
- How should I update both array and <ul> at the same time using react hooks?
- React and Nginx messing up urls when using axios, incorrect API calls
- How do i build deploy and server a React application locally using Ansible?
- How to upload file to Django rest framework API using Axios and react hook form?
- Getting Bad request for POST request using Axios and CORS in Django and react app
- 403 Forbidden Error when trying to post and put a axios request in a web app using Django and React
- POST 400: Bad request - Using Django REST API and React
- How to start and stop both the webcam stream and microphone in React JSX using WebRTC?
- How to show my reset password page in React using Django Rest Framework and Dj-rest-auth
- PM2, 502 Bad gateway, Nginx serving both React app and NodeJS API
- How to send a form input data containing both image and text from React front-end to Express backend using Multer
- How to set nginx to serve React and Django properly
- how to send data in GET request header using react and axios to Django rest framework?
More Query from same tag
- Redux - Filter / Delete multiple items from array of objects. Items to be filtered given in another array
- React Hooks useState() with Object TypeError: Cannot read property 'name' of undefined
- Props not showing error when there is typo in identifier
- React context state value not updated in Consumer
- ReactJS Moment is not formatting date correctly
- Next Js getStaticProps getting lost
- In Relay, what role do the node interface and the global ID spec play?
- ipcRenderer in React component constructor
- React - Login Variables cached in the browser
- fetching POST data from API (node js, react)
- React auth using useState for route
- PureComponent keeps rendering even though no state/prop changes
- Requesting an explanation for the concept of "Binding event handlers to class instance" in React
- React.js: Collapsible menu does not return to original state
- How to run a while loop in a React Component while this.state=X
- Reactjs dropzone not uploading all dragged and dropped files to firebase firestore database in reactjs
- React and Redux: Wrapping React Map Function with a HTML tag
- Access custom component methods through ref doesnt work as expected
- Unrecognised schema error
- Positioning Materialize CSS switches in a tabular fashion
- AutoCompleteEditor(react-data-grid) not working in chrome
- How to display external website as part of the app
- How to place 2 label-input (or datepicker) sets in one row horizontally in React?
- React context api update state instantly
- How do I navigate to another page?
- Applying an argument in mapStateToProps
- Ant Design form set values form props
- How to get Current week from given array of objects date in javascript
- How do I call the iScroll refresh methode in a parent react component?
- How to get className on click with React and iframe?