I am using AWS for the first time. I have created an ec2 instance and installed Apache server , made domain mapping from GoDaddy,
Now I want to create subdomains and point subdomains to the another document roots.
Like this :
www.mydomain.com should have domain root html\mydomain
www.test.mydomain.com document root to html\testsubdomain directory.
www.*.mydomain.com document root to html\subdomain directory
(* any subdomain other than test)
I tried to edit vhost file but could not find vhost file in apache server.
Generally where and how to achieve this?
Do I need to use Route53 for this?
DNS simply maps a domain name like www.mydomain.com or test.mydomain.com to an IP address. You will use Route 53 to set up this initial mapping.
However, your webserver needs to be configured to respond to each host. This is done using virtual hosts in apache. (Similar configuration are available for other web servers.
To create sub domains you need to add entry in configuration file for each sub domain being created. You can either create new config files for each subdomain or keep adding in httpd.conf. I added in httpd.conf. the code should look like this.
<VirtualHost *:80>
ServerName sub1.domain.tld
DocumentRoot "var/www/html/sub1"
</VirtualHost>
<VirtualHost *:80>
ServerName sub2.domain.tld
DocumentRoot "var/www/html/sub2"
</VirtualHost>
This adds 2 sub domains sub1 and sub2. After this you need to create an A record in route 53 pointing to the IP of EC2 instance.
In the Name field, you can place * so that this A record would be valid for al the sub domains that will be created.
If you want the subdomain have be SSL Certified and have requested a Wildcard Certificate from ACM and attached to the EC2 instance through Eastic Load Balancer then choose "Yes" for Alias else choose "No"
Value has to be IP Address of your EC2 instance if no Alias chosen and if Alias is chosen you can provide the ELB here in this field.
Hope this helps...
Related
I have two apache servers at two separate IP addresses and one domain name (example.com) administer on godaddy.com. I want to use this single domain to point traffic to my two separate servers over ssl.
I set up the first server through a fios router with port forwarding and associated the public IP address with a DDNS address (xxx.ddns.net). My godaddy config looks like this:
Type Name Value
-------------------------------
A # 184.168.131.241
CNAME www xxx.ddns.net
Forwarding
------------
domain https://www.example.com
... and my apache ssl.conf file looks like this:
<VirtualHost *:443>
...
ServerName www.example.com
DocumentRoot /var/www/html
</VirtualHost>
This works fine, but now I want to set up a subdomain ('mysub') so that traffic directed to mysub.example.com gets handled by my second server available at a separate IP address (MY.2ND.IP.ADDR). I've tried all sorts of settings on godaddy and in the ssl.conf file, but to no avail. In particular, I've tried:
Setting godaddy so that traffic sent to subdomain mysub.example.com is redirected straight to MY.2ND.IP.ADDR; it's not at all clear to me if this is possible. (Godaddy has a form under the title "Forwarding" and a subsection therein called "subdomain", but setting that subdomain to mysub and setting "forward to" to http://MY.2ND.IP.ADDR doesn't seem to do anything; what is this 'subdomain' field in the godaddy interface supposed to be used for?)
Directing all traffic to the first server, and configuring apache to proxy traffic for the subdomain on to the second server.
I've tried adding another virtual host element to ssl.conf like so:
<VirtualHost MY.2ND.IP.ADDR:443>
ServerName mysub.example.com
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://MY.2ND.IP.ADDR
ProxyPassReverse http://MY.2ND.IP.ADDR
</Location>
</VirtualHost>
... but this doesn't work either.
In summary, what is the best way to direct traffic for a subdomain to a separate IP address using godaddy and/or apache configurations?
I have a Hybris server installation hosting two sites hosted on two directories /site1 and /site2 pointing to two different domains such as www.site1.com and www.site2.com and both domains point to same ELB endpoint. In our current setup, we use the proxy web server (rewrite method) to add the /sitepath to the domain names. Eg: ELBcname/site1 and ELBcname/site2. We do this because both sites are deployed in the same instance.
As far as I know Hybris installation use apache-tomcat as their application web server. Can I do Apache Namevirtualhost configuration to point the two domains to these with different document root to avoid using the proxy server?
Eg:
<VirtualHost *:80>
DocumentRoot "/hybrisdocroot/site1/"
ServerName site1
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/hybrisdocroot/site2/"
ServerName site2
</VirtualHost>
Or is there any provision to add the path to Cname of ELB or ALB?
I would drop the proxy entirely, terminate SSL at the ELB with ACM Certificates on each domain (ie ssl common name *.site1.com and *.site2.com) and eliminate the path completely. Let the site answer at the fully qualified domain name (FQDN) only, and ideally only on HTTPS - HTTP is really disfavored now IMHO.
The path construction you indicate may have been used to simplify SSL termination and eliminate the number of certs needed for the service. Since ACM certs are free, the goal should be to provision each site with its own proper SSL cert.
Or is there any provision to add the path to Cname of ELB or ALB?
No. And in any case not needed if you eliminate the path from the URI to reach each site. And of course you can use ELB CNAMEs/ALIAS for a FQDN.
I am trying to set up 2 domains (domain1.com and domain2.com) with a few subdomains (app.domain1.com) in AWS and run them on single instance (Amazon Linux, PHP, MySQL).
I have set up 3 hosted zones in AWS Route53 with following configurations.
Hosted zone 1:
domain1.com
Type A
52.108.XX.YY
Hosted Zone 2
domain2.com
Type A
52.108.XX.YY
Hosted Zone 3
app.domain1.com
Type A
52.108.XX.YY
Additionally, I have added following code to the http.conf file in VirtualHost tag.
<VirtualHost *:80>
ServerName domain1.com
DocumentRoot "/var/www/html/domain1"
ErrorLog "logs/domain1-error_log"
CustomLog "logs/domain1-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName domain2.com
DocumentRoot "/var/www/html/domain2"
ErrorLog "logs/domain2-error_log"
CustomLog "logs/domain2-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName app.domain1.com
DocumentRoot "/var/www/html/app"
ErrorLog "logs/app.domain1-error_log"
CustomLog "logs/app.domain1-access_log" common
</VirtualHost>
However, only domain1.com and domain2.com are getting resolved. When I visit app.domain1.com, it gives me a "can't find server" error. Please help how to setup the subdomain - is there problem in Hosted Zone setup or httpd.conf?
Ok, so after about 2 hours of reading up various sites and tinkering, I am all set. Here is how to do this.
Basically, you should not have more than 1 hosted zone (HZ) per domain name, otherwise things are really going to be bad. If you have more than 1 HZ for a domain name, please delete the one that was created for the subdomain.
Each HZ will have 4 records -
Following two records are created by default. Do not edit/delete them.
NS - This is the name server record. If AWS Route53 is not your registrar, use ns-servernumber.awsdns-number.com. and other three (4 total) records to change name servers for your registrar.
SOA - Let this record be. DO NOT TOUCH THIS.
Create following two Record Set (blue button).
A - Leave Name blank. Select A-IPv4 address for Type. In Value enter the IP address for your Elastic Load Balancer or EC2 instance.
CNAME - Add * (asterisks/wildcard) in the name field. Select CNAME from the drop down for Type In Value enter the domain name.
Now create the http.conf file and structure virtual hosts like I have in the question.
Things should work now :)
You can follow the tutorial on this link: http://brianshim.com/webtricks/host-multiple-sites-amazon-ec2/
A common error, according to the link, is:
Did it work? If not, here is one possible cause. There might be
another configuration file interfering with this one. Check for
another .conf file in /etc/httpd/conf.d. Often your primary
httpd.conf will include another .conf file in this directory. Make
sure it doesn’t have some Virtual Host settings which are interfering
with yours.
After you set the configurations, you should run:
sudo service httpd restart
This can be done installing Apache HTTP Server on AWS-EC2 instance and configuring VirtualHost for each DNS or Sub-DNS as suggested by an Amazonian
For brevity read this thread discussion, this official example and techrepublic post.
Hope this helped!
I have SSL installed on my server, and I am using subdomain wildcards in the VirtualHost part of my ssl.conf file. The SSL certificate is valid for all subdomains, this works great.
Now i want to set up a subdomain and use this as a test, i.e. test.mywebapp.com. This test subdomain should point to a different document root. I want to put that in my ssl.conf by adding a new VirtualHost entry.
Currently the only entry is _default_:443. How can I add a new entry without overlapping with the exiting one? I tried test.mywebapp.com:443, but it keeps using the _default_ one.
Cheers,
Rick
Keep <VirtualHost _default_:443> (or *:443 or the.ip.address:443, but not the host name).
Use the ServerName directive within the virtual host to configure a different host.
I want to implement a blog in my site with usernames as subdomains like user1.domain.com.
I've read bunch of articles that was mentioned to create an A record like below in DNS:
*.domain.com A 127.0.0.1 ;OR you site ip address
Then use .htaccess to redirect requests from subdomains to a folder in your server.
But I find another approach that was said to just modify your httpd.conf as below:
<VirtualHost *:80>
DocumentRoot /abs/path/to/webroot
ServerName domainname.com
ServerAlias *.domainname.com
<Directory /abs/path/to/webroot>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Then retrieve subdomains via $_SERVER['HTTP_HOST'].
The question is why should someone use htaccess and put pressure on apache and create A DNS record when we can do a simple thing like ServerAlias *.domainname.com in httpd.conf?
I appreciate in advance for your views.
You need to setup both a wildcard DNS record and configure a server alias in httpd.conf to enable the hosting of arbitrary sub domains. They configure completely different things.
Add the wildcard DNS records is what allows clients to determine the IP address of your sub domain. With the wildcard DNS record about user1.domain.com will resolve to 127.0.0.1. If you do not have a DNS record no user1.domain.com will not be a valid name and it will not resolve to an IP address. the DNS record is to allow clients to connect to your server.
The httpd.conf configuration is local to your Apache server. It does not affect clients. The line ServerAlias *.domainname.com will configure Apache to tell it to process the arbitrary sub domains. Client's will not be directly affected by this setting.
You have added the ServerAlias, but for your computer to find that user1.domain.com and user2.domain.com should resolve to 127.0.0.1, you need to update your HOSTS file or DNS Table.
The configuration you have written is for Apache Server for handling the redirects when the user requests the domain. So, essentially, either you need a Dynamic HOSTS file or a service which resolves *.domain.com to your 127.0.0.1 server.
Hope this helps. :)