Hi All,

I have inherited a web site which is really a bit beyond me ... there's no option though, I've got to figure it out, so ...

The whole site uses Apache/Python/Django/Satchmo. I want to set up a sub-domain which uses a simple Apache/PHP set up.

I'm guessing that I need to add a virtual host to take care of this configuration. Only thing is, the current virtual host set up is causing me concern because I don't properly understand it and I don't want to break it.

It's the *:80 that's particularly bothering me - I get the feeling that if I put another virtual host section in then it will not read it because it's already dealt with it in the section detailed below? At the moment, if I go to subdomain.mydomain.co.uk then I get the same pages as if I had simply gone to mydomain.co.uk.

I am reluctant to experiment without being a little more sure of the outcome because this is on a live server and I cannot duplicate it on a development server (yet).

Here's the current code:

<VirtualHost *:80>
	ServerAdmin webmaster@localhost
	ServerName www.mydomain.co.uk

	Redirect permanent /pure 

	WSGIDaemonProcess simon
	WSGIScriptAlias / /home/simondev/projects/mydomain/apache/django.wsgi

	<Directory /home/simondev/projects/mydomain/apache>
		Order deny,allow
		Allow from all
	</Directory>

	Alias /media/ 	/home/simondev/projects/mydomain/media/
	Alias /static/	/home/simondev/projects/mydomain/static/ 

	<Directory /home/simondev/projects/mydomain/media>
		Order deny,allow
		Allow from all
	</Directory>

	<Directory /home/simondev/projects/mydomain/static>
		Order deny,allow
		Allow from all
	</Directory>

	ErrorLog /var/log/apache2/error.log

	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn

	CustomLog /var/log/apache2/access.log combined

</VirtualHost>

Any help would be appreciated, thanks,

Simon.

Dani AI

Generated

Apache chooses which virtual host to use first by IP:port and then by the Host header. If no vhost has a matching ServerName/ServerAlias for that IP:port, Apache serves the first-listed vhost for that address — which is why an undeclared subdomain will often show the same site as the main domain. The *:80 in a <VirtualHost> simply says “listen on port 80 for any IP”; it does not prevent adding another vhost for the same address/port. (httpd.apache.org)

Older Apache releases required an explicit NameVirtualHost declaration, but modern Apache (2.4+) enables name-based vhosts automatically and the NameVirtualHost directive is deprecated/has no effect. If the server is an older distro, that difference can cause surprising behavior — check the server’s Apache version before changing config. (httpd.apache.org)

Practical checklist to add a subdomain (safe, minimal risk): create a separate virtual-host config with ServerName set to the subdomain and a DocumentRoot for your PHP app; enable the site (on Debian/Ubuntu use a2ensite) and reload Apache; use apachectl -S (or httpd -S) to confirm which vhosts are defined and which one is the default; verify your DNS (A/CNAME) points the subdomain to the server. These steps avoid touching the existing Django/WSGI vhost. (manpages.debian.org)

A final caution when Django/mod_wsgi is present: a WSGIScriptAlias (or equivalent) placed in the vhost that becomes the default will handle requests at that vhost’s root — so keep your Django WSGI mapping confined to the Django vhost and put the PHP subdomain in its own vhost to avoid accidental routing. Also be aware that Apache 2.4 changed access-control directives (the newer Require model); back up configs, run apachectl -t (config test) and reload gracefully when ready. (modwsgi.org)

As noted, the “I’m looking in the wrong place” symptom is common — the file you edit must be the one Apache actually loads (sites-enabled, included files, etc.). Checking apachectl -S and making a small, backed-up change is the safest way to proceed. (httpd.apache.org)

Sorted ... I was looking in the wrong place!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.