【问题标题】:django + uwsgi + nginx subdomain for appsdjango + uwsgi + nginx 应用程序的子域
【发布时间】:2015-08-08 12:01:36
【问题描述】:

我正在按照本教程http://blog.richard.do/index.php/2013/04/setting-up-nginx-django-uwsgi-a-tutorial-that-actually-works/ 使用 django + nginx + uwsgi,它对我有用。

现在在我的项目中,我需要具有相同数据库的不同应用程序的子域,例如我有共享相同用户的 app1 和 app2。我需要 nginx 直接 url 来更正应用程序我的意思是 app1.example.com 直接从 nginx 转到 app1 不是处理 url 后来自 django。谁能给我 nginx.conf 和 uwsgi.ini 配置以及如何运行它们。

提前致谢

【问题讨论】:

    标签: django nginx uwsgi


    【解决方案1】:

    您可以使用django-subdomains。从他们的文档中:

    如果没有提供 subdomain 参数,则 URL 将按照相对于 SUBDOMAIN_URLCONFS[None]ROOT_URLCONF 的顺序进行解析

    >>> from subdomains.utils import reverse
    >>> reverse('home')
    'http://example.com/'
    >>> reverse('user-profile', kwargs={'username': 'ted'})
    'http://example.com/users/ted/'
    >>> reverse('home', scheme='https')
    'https://example.com/'
    

    对于subdomains,如果存在则将相对于SUBDOMAIN_URLCONFS[subdomain] 值解析URL,否则回退到ROOT_URLCONF

    >>> from subdomains.utils import reverse
    >>> reverse('home', subdomain='api')
    'http://api.example.com/'
    >>> reverse('home', subdomain='wildcard')
    'http://wildcard.example.com/'
    >>> reverse('login', subdomain='wildcard')
    'http://wildcard.example.com/login/'
    

    希望这会有所帮助。

    【讨论】:

    • 我的意思是 nginx 做导航工作不是 django。我看到了一个 apache 的例子,但我不能在 nginx 上使用它
    猜你喜欢
    • 2012-12-05
    • 2015-12-25
    • 2013-09-15
    • 2017-03-08
    • 1970-01-01
    • 2021-01-27
    • 1970-01-01
    • 2014-05-31
    • 2014-08-16
    相关资源
    最近更新 更多