开发者

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)?

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

<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 :)


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

<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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜