將子域指向Django中的特定url

[英]Pointing subdomain to specific url in Django


I have a Django site, working on mod_wsgi and Apache. (eg, example.com) I made a subdomain (eg, info.example.com) and want to point it to app in the existing project. Is it possible, that I have one urls.py file, and example.com/info and info.example.com point to the same view in Django project (without duplicating the whole project in different directory)?

我有一個Django站點,正在處理mod_wsgi和Apache。(例如example.com)我創建了一個子域(如info.example.com),並希望將其指向現有項目中的app。有可能,我有一個url。py文件和example.com/info和info.example.com指向Django項目中的相同視圖(沒有在不同目錄中復制整個項目)?

If so, how can I do it? Currently the example.com virtalhost config for the existing project looks like this:

如果是的話,我怎么做呢?目前,現有項目的example.com virtalhost配置如下:

<VirtualHost 12.34.56.78:80>
   ServerName example.com
   ServerAlias www.example.com

   DocumentRoot /srv/www/Example/Pub_html

   WSGIScriptAlias / /srv/www/Example/example.wsgi
   <Directory /srv/www/Example/Example>
      Order allow,deny
      Allow from all
   </Directory>

   Alias /robots.txt /srv/www/Example/robots.txt
   Alias /favicon.ico /srv/www/Example/favicon.ico
   ....
</VirtualHost>

Thanks in advance!

提前謝謝!

UPDATE: I did a quick fix here by creating another Django project which shares database tables and template folder with the existing one. It works, but it's not really DRY :)

更新:我在這里做了一個快速修正,創建了另一個Django項目,它與現有的數據庫表和模板文件夾共享。它確實有效,但也不是很干燥。

1 个解决方案

#1


1  

I'd do this with a reverse proxy, I reckon. If you have mod_proxy and mod_proxy_html available, try something like this:

我想我用的是反向代理。如果您有mod_proxy和mod_proxy_html,可以嘗試以下方法:

<VirtualHost 12.34.56.78:80>
    ServerName info.example.com

    ProxyPass       /  http://example.com/info

    SetOutputFilter proxy-html
    <Location />
        ProxyPassReverse /info/
        ProxyHTMLURLMap /info/ /
    </Location>
    ProxyHTMLURLMap http://example.com/info /
</VirtualHost>

the details may not be quite right, so let me know if you can't get it to work.

細節可能不太對,如果你做不到,請告訴我。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/04/13/72a0eb6503930ad4d6cb1066356668b9.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com