I Have two applications running on my server with domains
x.abc.com
admin.x.abc.com
x.abc.com is running on port 80
admin.x.abc.com is running on port 8080
I can able to access x.abc.com from browser, but when I try admin.x.abc.com, it is sending requests to x.abc.com only.
What is the proper way to configure two different web applications with different domain & port on single machine. Listed below my virtualhost files for x.abc.com & admin.x.abc.com respectively
<VirtualHost *:80>
ServerName www.x.abc.com
ServerAlias x.abc.com
RailsEnv test
DocumentRoot /home/cp/cp/public
<Directory /home/cp/cp/public/>
</Directory>
LogLevel warn
ErrorLog /home/cp/cp/log/error.log
CustomLog /home/cp/cp/access.log combined
RewriteCond %{HTTP_HOST} ^admin.x.abc.com
RewriteRule (.*) http://localhost:8080/$1 [R=301,L]
</VirtualHost>
<VirtualHost *:8080>
ServerName www.admin.x.abc.com
ServerAlias admin.x.abc.com
RailsEnv test
DocumentRoot /home/cp/cp_admin/public
<Directory /home/cp/cp_admin/public/>
</Directory>
LogLevel warn
ErrorLog /home/cp/cp_admin/log/error.log
CustomLog /home/cp/cp_admin/access.log combined
</VirtualHost>
You can add mutliple
VirtualHost
directives for a single port. Apache will process them according to the names, i.e.ServerName
andServerAlias
. Note that Apache defaults to the firstVirtualHost
configured, if no match is found. The following configuration should work.Your config seems to be good. Try the following:
It looks like what may be happening is that (1) all the traffic is being handled on port 80, and then (2) the
ServerAlias x.abc.com
is matching (and being used for)admin.x.abc.com
. Note, from the Apache documentation regarding matching:It is resolved after adding the below line in httpd.conf