Point domain and subdomain from Route53 to DigitialOcean using https - dns

I have two wordpress sites running on two digitialocean droplets.
They both have ssl certificates and redirects all requests to https.
Let's call the first adresse https://my-freenom-domain-1.ml
Let's call the second adresse https://my-freenom-domain-2.ml
I have a domain registered on route53. Let's call the domain my-domain.com.
I'm trying to map (not redirect) all requests from https://my-domain.com to https://my-freenom-domain-1.ml
and all request from https://subdomain.my-domain.com to https://my-freenom-domain-2.ml
How would you do this?
Update:
What I've tried (That didn't work)
Creating a simple CNAME.
CNAME for main domain (my-domain.com):
Cannot create a CNAME for main domain and gives the following error:
RRSet of type CNAME with DNS name my-domain.com. is not permitted at apex in zone my-domain.com.
CNAME for subdomain (subdomain.my-domain.com):
I am able to create a CNAME for the subdomain, but requests are redirected.
So when I go to subdomain.my-domain.com I'm redirected to https://my-freenom-domain-2.ml
Create a S3 "redirect-bucket"
I've tried creating a S3 bucket that redirects all requests for the subdomain.
So bucket named subdomain.my-domain.com, redirects all redirects to https://my-freenom-domain-2.ml (https).
I then created a CNAME for subdomain.my-domain.com pointing to subdomain.my-domain.com.s3-website-eu-west-1.amazonaws.com.
But all requests are still redirected...

You need to create a virtual host for your new domain on your Digital Ocean droplets for it to work.
So I would do following to make it work -
Create virtual host for the new domain on the webserver of droplets,
or add the new domain as server in the webserver config.
Add the SSL certificates of the new domain to the old webserver or alternatively terminate the ssl at the ELB.
Add the DNS CNAME or A record entry for the new domain pointing to the old domain servers.
Post this it should work.

This is based on #mdeora's answer correct answer with some details.
1. Create a virtual host for the domain (my-domain.com) in the droplet
Copy default conf:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/my-domain.com.conf
Add a ServerName to the conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName my-domain.com
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the site: a2ensite my-domain.com.conf
Reload apache: systemctl reload apache2
2. Install a ssl certificate on the droplets server
(I did it using certbot)
certbot --apache -d my-domain.com
(follow the certbot instructions)
3. Create an A record in route53
Create an A record and point it to the ip of the droplet.
(4. update wordpress settings)
If you're running a wordpress site be sure to change wordpress url settings in admin to https://my-domain.com.
Now, hopefully, everything should work.

Related

Apache Virtual Host isn't Serving Virtual Host 'index.html' at Domain Name

When I go to my ip address an index file is served.
However when I navigate to my domain name a page isn't served.
Apache won't serve content from my (domain name) web directory.
I don't plan to install PHP or a Database until the virtual hosts implementation is legit.
I've reinstalled my image more times than I can count to get my websites migrated to a virtual server. The biggest sticking point is configuring the virtual hosts. My latest attempt was using this blog article:
https://www.tecmint.com/install-apache-with-virtual-hosts-on-debian-10/
Before that it was this article in previous attempts:
https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mariadb-php-lamp-stack-on-debian-10
I looked at this article too:
https://linuxize.com/post/how-to-set-up-apache-virtual-hosts-on-debian-10/
I saw mentions of a user called www-data during my internet search but it isn't mentioned in the three blog posts I cited.
My hosting company keeps telling me to use Plesk but they didn't configure the shared hosting environment for the migration extension.
So I can't use Plesk to migrate and they charge me a monthly fee for the Plesk license if it is installed on the image.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster#example.com
DocumentRoot /var/www/html/example.com
<Directory /var/www/html/example.com>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
/etc/apache2/sites-available/example.com.conf
I looked at the domain name in other browsers and Chrome is forcing HTTPS at my request. I didn't get around to reinstalling the SSL/TLS because of the confusion with the virtual hosts. So basically the page has been live the entire time but Chrome wouldn't connect because a secure connection was unavailable.
This probably is not the correct answer, but I went into my file /etc/apache2/sites-enabled/000-default.conf
and changed the lines from:
#<VirtualHost *:80>
<VirtualHost *:8888>
#DocumentRoot /var/www/html
DocumentRoot /home/MyPath/Drives/02000/www

Redirect all subdomains to main domain by .htaccess

I'm trying to redirect all sub-domains to the root domain. For example, my domain is www.example.com. When someone tries to connect to notexists.example.com, I want to redirect it to www.example.com.
This is first going to be limited to dns.
If DNS is not first setup then the client's web browser won't have an ip address to visit if no DNS records exist for that subdomain, so you will have no way of contacting apache for it to implement a server side redirection.
What you need is a wilcard subdomain/record. This is in the form of an A record:
* 14400 IN A 1.1.1.1
You will access to the httpd.conf file (root access), if you are using cPanel without root access add * as a subdomain:
https://www.namecheap.com/support/knowledgebase/article.aspx/9191/29/how-do-i-create-a-wildcard-subdomain-in-cpanel
If you do have access you will need to set up a virtual host - add the following to your httpd.conf file:
#
# Your VirtualHosts section
#
NameVirtualHost 1.2.3.4
##
# this one accepts any subdomain
##
<VirtualHost 111.22.33.55>
DocumentRoot /www/subdomain
ServerName hostname.domain.com
ServerAlias *.domain.com
</VirtualHost>
http://httpd.apache.org/docs/2.2/vhosts/

Creating subdomain aliases

I have a server with Plesk 10.4 on CentOS6, which has an interface for creating aliases of a domain, but not aliases of a subdomain.
For example I have this subdomain set up:
test.my-domain.co.uk
And then I want to create aliases so that the following subdomains map to the same root:
alias-1.my-domain.co.uk
alias-2.my-domain.co.uk
alias-3.my-domain.co.uk
I've tried creating a vhost.conf file like this:
<Directory /var/www/vhosts/my-domain.co.uk/subdomains/test>
# aliases
ServerAlias alias-1.my-domain.co.uk
ServerAlias alias-2.my-domain.co.uk
ServerAlias alias-3.my-domain.co.uk
</Directory>
And then reconfiguring all domains:
/usr/local/psa/admin/sbin/httpdmng --reconfigure-all
However that fails.
Is this possible? Am I doing something wrong?
I suggest to
copy files and related data of subdomain to somewhere
delete subdomain
create add-on domain test.my-domain.co.uk
Now you should have ability to create aliases for test.my-domain.co.uk.
[update]
You are able create subdomain test.my-domain.co.uk and add-on domain test.my-domain.co.uk.
The difference in fact that for add-on domain you will have ability to create domain aliases.

Why is my virtualhost defaulting to the standard document root?

I have two domains registered: example.com and example.org. For one of these, I have also registered a subdomain: sub.example.com.
I successfully managed to set up a virtual host for my subdomain sub.example.com. So example.com points to the default document root /var/www and sub.example.com points to /var/www/sub.example.com.
But for some reason, I can't get example.org to point to anything else than the default document root. So example.com and example.org leads to the same website. I have created a virtual host for example.org, but Apache doesn't seem to register it.
# /etc/apache2/sites-available/example.org
<VirtualHost *:80>
ServerAdmin admin#example.org
ServerName example.org
DocumentRoot /var/www/example.org
</VirtualHost>
Have you enabled the website?
With a2ensite example.org you can enable your site. Then do service apache2 reload to reload the websites.

how to create a subdomain in a dedicated apache2 server

I want to create a subdomain I followed this steps :
cd /etc/apache2/sites-available
nano test.mydomaine.com
<VirtualHost *:80>
ServerAdmin mymail#gmail.com
ServerName test.mydomaine.com
ServerAlias www.test.mydomaine.com
DocumentRoot /var/www/testfolder/
<Directory "/var/www/testfolder">
AuthType Basic
AuthName "test"
AuthUserFile /var/www/testfolder/passwords
Require valid-user test
</Directory>
</VirtualHost>
exit and save
a2ensite test.mydomaine.com
/etc/init.d/apache2 reload
but It's not working am I missing something ?
In order for this to work, you additionally have to configure DNS resolution for the new hostname test.mydomain.com. If you are just playing with this locally and do not want to create a "real" DNS entry, you have to edit the file /etc/hosts so that your computer can resolve the hostname to an IP address. If you are running the web server on the same machine as the browser, you will want to map test.mydomain.com to 127.0.0.1. If the browser is on a different machine on your local network, you'll need to determine the server's IP address and then on the browser machine, edit /etc/hosts to add the mapping.
On Windows, the file is called C:\windows\system32\drivers\etc\hosts
A sample entry would be (for the browser running on the same machine as the server):
127.0.0.1 test.mydomain.com
If the server is at, say 192.168.0.5, the entry would be
192.168.0.5 test.mydomain.com
EDIT: If the server has a real routable IP address, then if you want the test.mydomain.com address to resolve on the global Internet you will have to get your service provider to add it to DNS. For testing purposes, you can still use /etc/hosts as described above. Just substitute the server's real IP instead of 127.0.0.1. Do this on the system where you are running the browser.

Resources