Saturday, August 22, 2015

redirect - CNAME: cross-site redirections toward subdomains




Good day everyone,



I saw many documentation about cname, but it couldn't help defining what was wrong with my approach.



I am stuck on a CNAME problem. I would welcome your advice and tips there. below is an example of what I am aiming at.



assume I have the domain example.com, IP 000.000.000.000. I have a client, say client1.com, whose IP is 111.111.111.111.(IP are totally theoretical, as the rest).



This is only one of many clients, for which I provide some services (online catalogues, or whatever). that is why, on my server, I created a subdomain via cpanel : client1.example.com, where I put all scripts concerning that client1.




In order for him to access these services, I invite him to create a redirection toward this subdomain. Therefore, he created a CNAME record (via CPANEL):
services.client1.com 26000 client1.example.com



Problem:
it seems that this cname records points at the right IP address (000.000.000.000). If anyone uses his browser to access services.client1.com, he arrives on the example.com server (regarding IP). However, once on the example.com server, it doesn't know where to land exactly: therefore, it lands on the default-page of the domain. to sum up:



user types the url services.client1.com -->arrives on 111.111.111.111 --> server indicates that this is a cname toward client1.example.com --> arrives on 000.000.000.000 -->server doesn't know what to do with this query -->serves the default page of the domain (some cpanel cgi-script).



My question is:

Is it possible, without any further implication of the client (that is, explicit redirection), that I configure the server example.com so that it points any CNAMEed query such as [l] http://services.client1.com toward the dedicated subdomain "client1.example.com" ? I was thinking of some kind of virtual host created on example.com 's server, but I couldn't work it through.



I am using a Centos virtual server for this purpose, where CPanel is installed (as well as apache server, php, and some other stuff).



I hope to be clear, and any lead might enlighten me!



Have a good one,



wisebes


Answer




I figured out how to do it.



Indeed, as leepfrog pointed out, you have to modify your vhosts configuration file, in order to make that happen. the steps are the following (CENTos):



0- create the subdomain client1.example.com



1- go to the httpd.conf file (/etc/httpd/conf/httpd.conf) and uncomment the "include" part for client1.example.com. indeed, you cannot add the alias in this file, as it may be regenerated regularly. However, you may include external files. the include line enables you to include any file with extension .conf that would be located on the specified path.



2- verify the path exists, or create it if needed, and create a file.conf there.Any name will suit, as long as it finishes with ".conf".You may write the following in that file:




DocumentRoot /home/user/public_html/client1
ServerAdmin webmaster@example.com
ServerName client1.example.com
ServerALias client1.example.com service.client1.com


NB: instead of "user" in document root, this would be your cpanel user



3- restart apache:
/sbin/service httpd restart




from now on, any query to service.client1.com will be considered as an alias to the IP 000.000.000.000. Once there, the server checks the virtual hosts, compares, and sees that service.client1.com is an alias for client1.example.com subdomain. it serves the content of that local subdomain.



Et voilĂ !


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...