在AWS EC2的多个子域上部署具有多个应用程序的django项目

问题描述 投票:1回答:2

我有一个django项目,其中包含2个应用程序,即adminapi。管理员应用程序依赖于api应用程序来访问模型。

我有2个子域,例如:admin.xxxx.comapi.xxxx.com

该项目当前已使用gunicorn + nginx部署在AWS EC2中。

UPDATE

所有管理员请求都传递给:some.ip.address.0:8000/admin/,所有api请求都传递给some.ip.address.0:8000/

有什么方法可以将我的some.ip.address.0:8000 / admin /指向admin.xxxx.comsome.ip.address.0:8000 /] >到api.xxxx.com

UPDATE 2:

myproject_nginx.conf文件:

upstream myproject_backend_server {
  # fail_timeout=0 means we always retry an upstream even if it failed
  # to return a good HTTP response (in case the Unicorn master nukes a
  # single worker for timing out).
  server unix:/home/ubuntu/myproject_backend/myproject_backend.sock fail_timeout=0;

}

server{
    listen 80;
    listen [::]:80;
    server_name admin.mydomain.in;

    location / {
      proxy_pass http://13.***.***.***:8000/admin/;
    }
    location /static/ {
       alias   /home/ubuntu/myproject_backend/static/;
     }

    location /media/ {
       alias   /home/ubuntu/myproject_backend/media/;
     }

 }


server {

    listen 80;

    server_name 13.***.***.***:8000  api.mydomain.in www.api.mydomain.in;

    client_max_body_size 4G;

    location /static/ {
        alias   /home/ubuntu/myproject_backend/static/;
    }

    location /media/ {
        alias   /home/ubuntu/myproject_backend/media/;
    }

    location / {

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_set_header Host $http_host;

        proxy_redirect off;

        # Try to serve static files from nginx, no point in making an
        # *application* server like Unicorn/Rainbows! serve static files.
        if (!-f $request_filename) {
            proxy_pass http://myproject_backend_server;
            break;
        }
    }

}

myproject urls.py文件:

from django.urls import path, re_path, include
from django.conf.urls.static import static
from django.conf import settings
from django.views.static import serve

urlpatterns = [
    re_path(r'^', include('api_app.urls')),
    ...
    path('admin/', include('admin_app.urls')),

    ...

    re_path(r'^static/(?P<path>.*)$', serve,
            {'document_root': settings.STATIC_ROOT}),
    re_path(r'^media/(?P<path>.*)$', serve,
            {'document_root': settings.MEDIA_ROOT}),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

它打开我的管理员登录页面,但我尝试登录时显示:/ admin / admin在此服务器上找不到。

请提示出什么问题?

我有一个django项目,其中包含2个应用程序,即admin和api。管理员应用程序依赖于api应用程序访问模型。我有2个子域,例如:admin.xxxx.com和api.xxxx.com。这个...

django amazon-web-services subdomain
2个回答
1
投票

据我所知,当用户在浏览器中键入此地址http://admin.mydomain.in并且此admin页面由您的django应用处理时,您要显示一个admin页面,因此您正在使用nginx代理到http://13.***.***.***:8000/admin/可以访问该页面。


1
投票

是,为此,您必须将两个域指向托管django应用程序的EC2实例(如果使用的是ELB,则指向ELB)并配置Nginx,以便它将请求从一个域重定向到admin并从api路径以外的其他位置。

© www.soinside.com 2019 - 2024. All rights reserved.