DigitalOcean 应用程序平台:在非根 URL 上使用 Gunicorn 托管 Dockerized Django 应用程序

时间:2021-04-25 02:04:33

标签: django django-rest-framework gunicorn digital-ocean

我最近在 DigitalOcean 应用程序平台上部署了一个 dockerized Django 应用程序,以及使用应用程序规范文件的 react 静态站点。由于是静态站点,我选择在非根 URL(例如 https://example.com/api)上提供 Django,并在根 URL (https://example.com) 上提供 react 应用程序。

如果我访问 Django URL,Django 会出现但抛出“找不到路径错误”。我的 Django 应用程序上的所有路由都不起作用。解决方案似乎也没有在 google 上,我不知道为什么。

这是我的 app.yaml 的样子:

name: test
region: nyc
services:
  - name: backend-api
    github:
      branch: deployment_app_platform
      repo: NdibeRaymond/test
      deploy_on_push: true

    http_port: 8000
    instance_count: 1
    instance_size_slug: basic-xxs
    source_dir: backend/
    dockerfile_path: backend/compose/django/Dockerfile
    routes:
      - path: /api

static_sites:
  - name: frontend
    environment_slug: node-js
    github:
      branch: deployment_app_platform
      repo: NdibeRaymond/test
      deploy_on_push: true

    source_dir: frontend/test/
    build_command: npm run build
    routes:
      - path: /

gunicorn 配置

exec /usr/local/bin/gunicorn test.wsgi --threads=3 --bind 0.0.0.0:8000 --chdir /backend/test

根网址文件

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api-auth/', include('rest_framework.urls')),
    path('summernote/', include('django_summernote.urls')),
    path('', include('APIS.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我也试过

urlpatterns = [
    path('api/admin/', admin.site.urls),
    path('api/api-auth/', include('rest_framework.urls')),
    path('api/summernote/', include('django_summernote.urls')),
    path('api/', include('APIS.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

你能发现我遗漏了什么吗?

0 个答案:

没有答案