Dja*_* DO 5 django production reactjs
我正在运行一个带有Django+DRF, CELERY+REDIS, ReactJs+REDUX&的应用程序JWT,但我很难连接backend到frontend部署。
我曾经用来create-react-app生成 React 代码;并npm run build生成生产版本。
我一直在四处寻找,但找不到有关如何将它们链接在一起的教程。
如果你们口袋里有任何我可以关注的链接,我将非常感谢你们。
您不需要将 React 文件“移至”Django。只需分开服务即可。
这就是我为我的项目提供服务的方式:
我通过/api/url 提供 API,所以这里是我的 Nginx 配置的粗略表示:
server {
# urls that start with /api or /admin
location ~ ^/(api|admin) {
# pass them to uwsgi or gunicorn
...
}
# urls that start with /media
location /media {
# serve from your project's media folder
...
}
# urls that start with /static/admin
location /static/admin {
# these requests are made to admin's static files
# serve them from your staticroot folder
# i.e. where your files are stored after you run `collectstatic`
...
}
# everything else
location / {
# serve from frontend build folder
root /path/to/the/build/folder;
index index.html;
# this is important
# first try to find files matching url, like css, or js, or favicon
# if nothing found, serve the index.html
try_files $uri /index.html;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4861 次 |
| 最近记录: |