dra*_*rys 5 cloud django nginx reactjs digital-ocean
我有一个 digitalocean 服务器,并且已经使用 Gunicorn 和 nginx 部署了 Django 后端服务器。
如何在同一台服务器上部署 React 应用程序?
这是我的文章: Docker-Compose for Django and React with Nginx reverse-proxy 和 Let's cryptert。
下面是我的 Nginx 配置:
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/;
}
}
Run Code Online (Sandbox Code Playgroud)
Nginx docker 文件:
# 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;"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5068 次 |
| 最近记录: |