Apache/Django subdomains problem

…衆ロ難τιáo~ 提交于 2019-12-13 04:01:22

问题


Now I have apache configuration which works only with localhost domain (http://localhost/).

Alias /media/ "/ścieżka/do/instalacji/django/contrib/admin/media/"
Alias /site_media/ "/ścieżka/do/plikow/site_media/"
<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE settings
    PythonPath "['/thomas/django_projects/project'] + sys.path"
    PythonDebug On
</Location>
<Location "/site_media">
SetHandler none
</Location>

How can I make it working for some subdomains like pl.localhost or uk.localhost? This subdomains should display the same page what domain (localhost).

Second question: It is possible change default localhost address (http://localhost/) to (http://localhost.com/) or (http://www.localhost.com/) or something else?


回答1:


You can use the ServerAlias directive in apache for different hosts

NameVirtualHost *
<VirtualHost *>
ServerAlias pl.localhost
ServerAlias uk.localhost
Alias /media/ "/ścieżka/do/instalacji/django/contrib/admin/media/"
Alias /site_media/ "/ścieżka/do/plikow/site_media/"
<Location "/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE settings
    PythonPath "['/thomas/django_projects/project'] + sys.path"
    PythonDebug On
</Location>
<Location "/site_media">
SetHandler none
</Location>
</VirtualHost>

but if you dont use internet domains with a configured dns you need also to update yor hosts file with the hosts you are trying to use.




回答2:


yes thanks Meska, I resolved the problem. I added to /etc/hosts file something like:

127.0.0.1 pl.localhost

127.0.0.1 uk.localhost

127.0.0.1 www.localhost.com



来源:https://stackoverflow.com/questions/2824660/apache-django-subdomains-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!