Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

URL redirection with wildcard DNS, Apache2

Hi Experts,

I need to redirect 3 URLs via same Public IP. Currently the all the domain's DNS are hosted with Godaddy. (I'm pretty much sure about the Goddady configuration)

Below is the implementation requirement;

1. www.mydomain1.com to APP1 = works well
2. *.mydomain1.com to APP2 = works well (wild card DNS)
3. sub.mydomain2.com to APP3 = NOT WORKING

Below is the current configuration on Apache2 on CentOS 5.4

Please advise me on no 3 and thanks a lot for your time !


#### APP1 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app1
 servername www.mydomain1.com
</VirtualHost>


#### APP2 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app2
 servername mydomain1.com
 ServerAlias *.mydomain1.com
</VirtualHost>


#### APP3 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app3
 servername sub.mydomain2.com
</VirtualHost>

##############

Open in new window

0
Shakthi777
Asked:
Shakthi777
  • 8
  • 7
  • 3
  • +1
2 Solutions
 
underskyCommented:
yes it' not working, try change 2 and 3 places..

2 app tells, that

ALL . mydomain1.com go to mydomain1.com

so get this in last place, or your apache server wont work with it, becouse second VirtualHost, accept rule:

sub.mydomain1.com also ;)
0
 
Shakthi777Author Commented:
can you just advise me how to change it order to function as required ?

thanks a lot !
0
 
aliganjeiCommented:
undersky,

I think this is not the case, because the third virtual host points to mydomain2.com and is not a subset of second vhost
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
aliganjeiCommented:
What happens when you send a request for sum.mydomain2.com? You've got error messages on your browser? or some other application comes up instead of number 3?
0
 
Shakthi777Author Commented:
aliganjei: when I access sub.mydomain2.com it just gave a blank page on Firefox and "Server Error" on Chrome
0
 
aliganjeiCommented:
my you please check error_log of your server and tell us what happens?
0
 
aliganjeiCommented:
maybe virtual host is working fine and something is wrong with your application?
0
 
Shakthi777Author Commented:
on APP3 config I have changed mydomain2 to mydomain1 and now it's redirecting to the APP2 which is wild card DNS.

How do I fix this ???
#### APP1 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app1
 servername www.mydomain1.com
</VirtualHost>


#### APP2 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app2
 servername mydomain1.com
 ServerAlias *.mydomain1.com
</VirtualHost>


#### APP3 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app3
 servername sub.mydomain1.com
</VirtualHost>

##############

Open in new window

0
 
aliganjeiCommented:
here you should refer to Undersky's comment.
Just cut the lines for App3 and paste them befor App2
0
 
Shakthi777Author Commented:
Dose it redirect the three URL respectively to the three applications ?
0
 
aliganjeiCommented:
It should
0
 
Shakthi777Author Commented:
aliganjei:  nope it's made non of them working...

0
 
aliganjeiCommented:
try httpd -S
see if it reports any errors
0
 
Shakthi777Author Commented:
aliganjei: "Syntax OK"
0
 
aliganjeiCommented:
Well,
First look if this config works for you and all three applications are accessible:

 
#### APP1 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app1
 servername www.mydomain1.com
</VirtualHost>


#### APP2 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app2
 servername mydomain1.com
# ServerAlias *.mydomain1.com
</VirtualHost>


#### APP3 ####

<VirtualHost *:80>
 DocumentRoot /var/www/hosted/app3
 servername sub.mydomain1.com
</VirtualHost>

##############

Open in new window

0
 
crazedsanityCommented:
In the event that you're still having issues, I would suggest troubleshooting it a bit more: remove everything but the third app ("/var/www/hosted/app3") and make sure it works.  The problem could be as simple as that application not working.
0
 
underskyCommented:
hmm, look:


<VirtualHost *:80>

means that all * addresses, here on port 80, trow to -> servername

when you "#" comment SrverAlias, you send now all sites, in your IP/address:80 to APP2 :) nothing changes..

try this one:

<VirtualHost *:80>    
      ServerName    mydomain1.com
      ServerAlias  www.mydomain1.com
        DocumentRoot "/var/www/hosted/app1"
      <Directory />
            Options FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
      </Directory>
</VirtualHost>

<VirtualHost *:80>    
      ServerName    sub.mydomain2.com
      ServerAlias  www.sub.mydomain2.com
      DocumentRoot "/var/www/hosted/app3"
      <Directory />
            Options FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
      </Directory>
</VirtualHost>

<VirtualHost *:80>    
      ServerName    *.mydomain1.com
      ServerAlias  *.mydomain1.com
      DocumentRoot "/var/www/hosted/app2"
      <Directory />
            Options FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
      </Directory>
</VirtualHost>


after changes
do

service apache2 restart
0
 
underskyCommented:
you can try change ports, and check, it works or not.. this one must work fine..

btw also check:


host mydomain1.com
host mydomain2.com
host sub.mydomain1.com


did DNS show it right?
0
 
crazedsanityCommented:
It is very common to have multiple host entries listening on port 80; because of it, however, the ServerName takes precedence.  There may be something with the wildcards used in that third entry; the usage of wildcards seems like the only noticeable difference.

Again, I would make certain that all three apps are working as expected before going into any further troubleshooting steps.  If the application is causing some sort of error, it could be leading you down the wrong path (so to speak).
0
 
Shakthi777Author Commented:
tnx !
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

  • 8
  • 7
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now