AWS Guide on Route 53, VirtualHost and website in document root - amazon-ec2

I have researched this topic for one week!
My situation is as follows:
I have an instance, already set up with an elastic IP address (e.g. 5.6.7.9)
I have a website in my document root folder (e.g. var/www/html/website_folder/index.html)
I have purchased and registered a domain name from AWS itself (e.g. mywebsite.com)
I have created a hosted zone for this (mywebsite.com) website, it automatically generated two record sets - NS and SOA. I have read numerous articles on CNAME and A records with VirtualHost configurations and none seem to work.
My security configuration allows all sources - 0.0.0.0/0 for http, TCP...
An example of what i tried:
*.mywebsite.com CNAME (value = mywebsite.com)
I could not add A record because ip address for website is 5.6.7.9/website_folder which cannot be entered in the field provided
NameVirtualHost *:80
<VirtualHost *:80>
ServerName mywebsite.com
DocumentRoot var/www/html/website_folder
ServerAlias *.mywebsite.com
</VirtualHost>
This did not work. Please help me.

The settings were as follows:
In route 53
add A type with your instance elastic ip (e.g mywebsite.com A 5.6.7.9)
add CNAME e.g. (*.mywebsite.com CNAME mywebsite.com)
add CNAME e.g. (#.mywebsite.com CNAME 5.6.7.9/website_folder)
In /etc/httpd/conf/httpd.conf add the following lines where it has "NameVirtualHost *:80"....at the bottom of the file:
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias www.mywebsite.com *.mywebsite.com
DocumentRoot var/www/html/website_folder
</VirtualHost>

Related

Laravel Wildcard Subdomain routing

I have some problems with wildcard subdomain routing with Laravel.
I want to create subdomain for every user.
So I'm doing like this:
My API.js in Laravel routes:
Route::domain('{user}.mydomain.com')->group(function () {
Route::get('user', [UserController::class, 'getUserDetails'])->name('user');
});
And this is my vhosts
<VirtualHost *:80>
ServerAdmin domain#gmail.com
DocumentRoot "C:\xampp\htdocs\Project\public"
DirectoryIndex index.php
ServerName mydomain.com
ServerAlias *.mydomain.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
And C:\Windows\System32\drivers\etc\hosts
127.0.0.2 mydomain.com
127.0.0.2 *.mydomain.com
What am I doing wrong?
EDIT: I'm using Windows
You simply need a DNS service. i use Acrylic DNS Proxy on Windows and they have a nice documentation how to setup in windows environment.
Link for Acrylic Documentation
Simply follow the documentation and add your hosts in Acrylic UI host configuration at the bottom as listed here
127.0.0.1 *.mydomain.com domain.com
Don't forget to restart Acrylic DNS Proxy service after setting up, should work like a charm.
Windows does not support wildcard entries in the hosts file. You'll need to specify alle the individual subdomains.

Host 2 Websites 1 on IIS with 80 Port and 1 on Xampp 8081 port

I am having a website first.com which is deployed on a windows server with ip like (11.111.111.11) using 80 port (DNS is pointed on first.com of host server), Now I have installed Xampp and run on 8081 port and deployed code which can be accessed using ip 11.111.111.11:8081/second, what I have to do is another domain second.com to point this second folder of xampp so second.com is equals to 11.111.111.11:8081/second, I have changed DNS of second.com to host DNS of first.com as it is done for this domain.
And changed my vhost of xampp like
<VirtualHost *:8081>
DocumentRoot "D:/xampp/htdocs"
ServerName www.second.com
<Directory "D:/xampp/htdocs/second">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now when I am hitting this second.com it points the same website of first.com but when I hit second.com:8081/second it points to the new website which logically is working fine, now I want that second.com should open the new website without showing any port/folder.
I believe it is Possible, Please suggest.
Thanks in advance
I think you maybe enabled the virtual host on the xampp,
then you can do the domains pointed to same port by editing the file /httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/website_a
ServerName www.website_a.com
ErrorLog "/opt/lampp/htdocs/website_a/error_log"
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/website_b
ServerName www.website_b.com
ErrorLog "/opt/lampp/htdocs/website_b/error_log"
</VirtualHost>
If you want to know more some reference, here is one for you:
https://github.com/oliguo/Server-Deployment/blob/master/XAMPP.md

laravel virtual host setup not showing front-end

I have a new laptop, and am now trying to run a laravel application.
First, am trying to setup a virtual host for the project so that I can access blog.local
I went my hosts file and setup the drivers like the following:
127.0.0.1 localhost
127.0.0.1 test.local
127.0.0.1 blog.local
The for the apache configuration I have the following:
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog"
ServerName blog.local
</VirtualHost>
When I try to access my url I do not see the site but the files only:
For this and future projects, how can I create a local url and see the front-end when I visit it?
You need to address your public folder,
<VirtualHost *:80>
DocumentRoot "C:\XAMPP\htdocs\blog\public"
ServerName blog.local
</VirtualHost>
The document root is a directory (a folder) that is stored on your host's servers and that is designated for holding web pages. When someone else looks at your website, this is the location they will be accessing.
Change the DocumentRoot to according to your PHP project is located.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/blog/public"
ServerName blog.local
</VirtualHost>
Restart the servers after making any changes! If you don’t reset the server to apply the changes, nothing will work even though you know you’ve done everything right.

AWS Route 53 to redirect existing domain name to EC2 IP address

My website is running in AWS EC2, I want to redirect my dns name to public ip of ec2 server. How to configure this?
Edit httpd.conf file with following code.
<VirtualHost *:80>
ServerName domainname.com
DocumentRoot /var/www/html/awsec2
</VirtualHost>
Uncomment NameVirtualHost *:80
Restart Apache

how can i recognize in pc that which domain name should be linked to which folder

I want to forward different domain names to single IP Address (local for testing), but how can i recognize in pc that which domain name should be linked to which folder?
for example, in windows host file, I wrote
127.0.0.1 abc.com
127.0.0.1 test.abc.com
127.0.0.1 test1.abc.com
Being found within the same VirtualHost section binds the ServerName and DocumentRoot directives together.
<VirtualHost *:80>
ServerName www1.example.com
DocumentRoot /srv/web/www1
</VirtuaHost>
<VirtualHost *:80>
ServerName www2.example.com
DocumentRoot /srv/web/www2
</VirtuaHost>

Resources