Why is my Django project displayed at the same time in a subdomain and localhost?

The thing is, I have a django project installed in a subdomain in localhost, and at the same time I have a local host for other things without Django.

When I access a1.localhost, it displays my django welcome page in order, but when I want to access only the local host, it also displays the same django welcome page, not index.html.

So far this is what I have:

Hosts: 127.0.0.1 localhost 127.0.0.1 a1.localhost vhosts.conf: #-- a1.localhost <VirtualHost *:80> ServerName a1.localhost WSGIScriptAlias / "C:/workspace/website1/apache/django.wsgi" <Directory "C:/workspace/website1/apache"> Order allow,deny Allow from all </Directory> </VirtualHost> #-- localhost <VirtualHost *:80> ServerName localhost DocumentRoot "C:/workspace/website1/django_project" </VirtualHost> django.wsgi import os import sys path = "C:/workspace/website1/apache/django_project" if path not in sys.path: sys.path.append(path) os.environ['DJANGO_SETTINGS_MODULE'] = 'django_project.settings' import django.core.handlers.wsgi 

I want to get the normal index.html file displayed in localhost and my django project in a1.localhost.

Thanks.

+4
source share
1 answer

I think this is where the first virtual host happens, which takes all the traffic to port 80 and redirects it to the django application. The second virtual host does not receive traffic at all. All this works when they are different ports, because in this case apache knows which virtual host should receive the traffic.

You may need to add a line in front of these declarations to configure the virtual host name, as noted by Kei Ju:

NameVirtualHost *: 80

See this article for more information: http://digitalpbk.blogspot.com/2007/01/making-subdomains-on-localhost.html

+2
source

Source: https://habr.com/ru/post/1443149/


All Articles