nginx-多个django应用程序同一域不同的Urls [英] nginx - multiple django apps same domain different Urls

查看:99
本文介绍了nginx-多个django应用程序同一域不同的Urls的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个域上服务多个django项目(实际上是django rest API应用程序),但是要在单独的url上服务每个项目.像这样:

I want to serve multiple django projects (actually django rest API apps) On one domain but serve each of them on seperated url. like this:

  1. http://test.com/app1/ ...
  2. http://test.com/app2/ ...
  1. http://test.com/app1/...
  2. http://test.com/app2/...

,依此类推.我将使用nginx对其进行配置.但是我遇到了一些需要您帮助的问题:

and so on. I will be using nginx to config it. But i'm facing some problems that wants your helps:

  1. 这些应用彼此之间应具有不同的Cookie.因为他们有不同的身份验证系统.因此其中的令牌和cookie对另一令牌无效.该如何处理?
  2. 您推荐哪些nginx配置.

注意:

我不想要详细信息,因为我知道概念.只是一些提示和有用的命令即可.

I don't want full detail cause i know concepts. just some hints and usefull commands will do.

更新:

例如,我有一个django应用程序,其URL为test.而且我希望此路径在/app1/test服务器上提供.问题在于,当将请求发送到/app1/test时,Django无法将其识别为/test,而不是/app1/test,并且因为/app1未在urls.py中注册,将产生404错误.

For example i have a django app which has a url test. and i want this path to be served on server with /app1/test. The problem is that when is send request to /app1/test, Django doesn't recognize it as /test, instead as /app1/test and because /app1 is not registered in urls.py will give 404 error.

这是我的nginx配置的示例:

here is a sample of my nginx config:

server {
listen 80;
server_name test.com;

location /qpp1/ {
    include uwsgi_params;
    proxy_pass http://unix://home//app1.sock;
}

location /qpp2/ {
    include uwsgi_params;
    proxy_pass http://unix://home//app2.sock;
}
}

推荐答案

您可以尝试使用 proxy_cookie_path 指令:

You can try to play with proxy_cookie_path directive:

server {

    ...

    location /app1/ {
        proxy_cookie_path / /app1/;
        proxy_pass http://backend1/;
    }

    location /app2/ {
        proxy_cookie_path / /app2/;
        proxy_pass http://backend2/;
    }
}

更新

这是要测试的另一种配置.

Here is another variant of configuraion to test.

upstream qpp1 {
    server unix:/home/.../app1.sock;
}

upstream qpp2 {
    server unix:/home/.../app2.sock;
}

server {
    listen 80;
    server_name test.com;

    location /qpp1/ {
        include uwsgi_params;
        proxy_cookie_path / /qpp1/;
        proxy_pass http://qpp1/;
    }

    location /qpp2/ {
        include uwsgi_params;
        proxy_cookie_path / /qpp2/;
        proxy_pass http://qpp2/;
    }
}

这篇关于nginx-多个django应用程序同一域不同的Urls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆