setup sub domain amazon using Route 53 - amazon-web-services

im really confused regarding setting up sub domain on amazon using their DNS service (hosted zones) and another 3rd party registrar. This is because i found different solutions some include add CNAME record and others say add using virtual host in the apache server
so should i do both or adding the CNAME in the records is enough.
so far, I have tried the first solution
I have added CNAME record (for example, let s assume my website is example.com)
so I have added CNAME subdomain.example.com pointing to example.com/subdomain. I have waited for 1 day so the DNS settings to be propagated, still when I check the website i get an error.
i've also tried to add virtual host in my conf file, but it didn't work at all.

I think the answer is very clear in the referenced link, but to clarify more what you should do , Follow the following steps:
1 - Go to your AWS managment console -> Route 53.
According to your question, it looks that you are already using AWS DNS service, which means you have already created hosted zone (in case you don't have hosted zone create one )
For more info, follow the documentation http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/creating-migrating.html
2 - Click on the hosted zone, then click on create record set
the record set should be type A pointing to your #IP of your server (Elastic IP or Load balancer IP)
Example:
subdomain.example.com -> Type A -> #IP
By the way you can use CNAME record for www.subdomain.example.com that points to subdomain.example.com
3 - the last step is to add Virtual Host in your configuration file of your appache server.
open this file /etc/httpd/conf/httpd.conf.d
Add the following Virtual Hosts
<VirtualHost *:80>
ServerAdmin webmaster#yourdomain.com
DocumentRoot "/var/www/html/domain_folder"
ServerName example.com
ErrorLog "logs/example.com-error_log"
CustomLog "logs/example.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster#yourdomain.com
DocumentRoot "/var/www/html/subdomain_folder"
ServerName subdomain.example.com
ErrorLog "logs/subdomain.example.com-error_log"
CustomLog "logs/subdomain.example.com-access_log" common
</VirtualHost>
4 - Restart httpd by typing this at the command line:
> sudo service httpd restart
PS :
=> if this doesn't work, 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. If so, comment them out.
=> also make sure NameVirtualHost *.80 is uncomment

Related

Access Local Domain Name Website as API server in WAMP

I have two local Domain which work fine, however, the otherA domain is the API server that the otherB domain consumes API. The problem is it can't access the otherA domain, and returns network error something like
option 1
let apiserver = 'http://localserverA.local'
axios.get(`${apiserver}/apicall`).....
catch( ---> return network error
But this works
option 2
let apiserver = 'http://127.0.0.1:8000'
axios.get(`${apiserver}/apicall`).....
returns 200 ok
The problem with option 2 is to run php built in server which not a good idea because some set up in databases requires domain local host to access its data.
<VirtualHost *:80>
ServerName localserverA.local
ServerAlias localserverA.local
DocumentRoot C:/projects/r/projects/A/web
<Directory "C:/projects/r/projects/A/web">
AllowOverride All
Require all granted
Allow from All
Allow from 127.0.0.1
Allow from ::1
#FallbackResource /app.php
</Directory>
</VirtualHost>
I can even ping my domain name, it works well in browser but got network error when endpoint called via javascript. Works well in production
Any Idea?
This may help you:
Go to directory (from where your landing page load, if you have laravel project you need to go to public directory) to your project in command promt and fire command.
php -S <ip addresss>: <any port no>
like this
php -S 192.168.1.62:4200
Now you can access that project using 192.168.1.62:4200
You need to change your %SystemRoot%\system32\drivers\etc\hosts file. Add next line:
127.0.0.1 localserverA.local

AWS multiple domains point to single EC2 Linux instance

Is it possible to setup multiple domains to point with one single linux ec2 instance?
For example :
I have registered following 3 domain and I need to point to below path in single Linux EC2 instance:
www.domain1.com - var/www/html/domain1
www.domain2.com - var/www/html/domain2
www.domain3.com - var/www/html/domain3
Very much possible. You can add A records in the dns zone of your domain registrar pointing to the elastic ip of your ec2 instance to get the requests routed.If you are having public dns instead of an elastic ip, you can add CNAME record instead of A record
Further you can use apache inside your ec2 to route the requests as you wish to required application path. Steps below. (This assumes that you have the document roots to be served for the 3 domains copied to the respective paths mentioned in your question)
Step 1 : Configure your second and 3rd domains also to point to the same EC2 public IP using domain registrar (go daddy in your case) DNS Zones configuration. (Assuming all 3 domains are yet to go live)
Step 2 : Create virtual hosts file for the 3 domains which you want. Content given below.
File 1: /etc/httpd/conf.d/domain1.com.conf with content
<VirtualHost *:80>
ServerName www.domain1.com
ServerAlias domain1.com
DocumentRoot /var/www/html/domain1
ErrorLog /var/www/html/www.domain1.com/error.log
CustomLog /var/www/html/www.domain1.com/access.log combined
</VirtualHost>
File 2: /etc/httpd/conf.d/domain2.com.conf
<VirtualHost *:80>
ServerName www.domain2.com
ServerAlias domain2.com
DocumentRoot /var/www/html/domain2
ErrorLog /var/www/html/www.domain2.com/error.log
CustomLog /var/www/html/www.domain2.com/access.log combined
</VirtualHost>
File 3: /etc/httpd/conf.d/domain3.com.conf
<VirtualHost *:80>
ServerName www.domain3.com
ServerAlias domain3.com
DocumentRoot /var/www/html/domain3
ErrorLog /var/www/html/www.domain3.com/error.log
CustomLog /var/www/html/www.domain3.com/access.log combined
</VirtualHost>
Once this is done, you can restart apache and check.
Hope this helps
Note: In case this is not working for you or if you are facing some errors, please do include the apache version, OS and version as well in the response :)
Yes, it is like normal Linux server. You can use as many domains as you want. Just point all of them to the IP address of the instance (recommending using Elastic IP). A record is better as it is faster to translate.
Then it is upon Apache Server, it controlls what directory to use with each domain.

Route a specific path to a specific EC2 instance using Route 53

I'm not sure if this is even possible, but if so I'm looking for the best way to do it.
Say I want to host my blog for example.com on it's own EC2 instance, and I want the path to my blog to be example.com/blog
Is it possible to route all requests to example.com/blog/* to one instance, and all other requests to that domain elsewhere?
My web server is Apache.
Thanks!
You can now do this with Application Load Balancer and path-based routing: https://docs.aws.amazon.com/elasticloadbalancing/latest/application/tutorial-application-load-balancer-cli.html#path-based-routing-aws-cli
Certainly it's possible, but not with DNS nor with an ELB. The most common solution to this is to use a web server that issues a 301 or 302 redirect.
In your case, example.com would point to whatever the main site is. The web server (nginx or Apache httpd, perhaps) hosting example.com would have a redirect for example.com/blog/* that is found at another destination.
Here's an SO post on using Nginx for a redirect and for using Apache for a redirect.
Yes, but you would have to proxy your requests through an instance handling example.com. How you configure this depends on your web server.
Some examples on how to configure this:
nginx: http://wiki.nginx.org/HttpProxyModule
Apache: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Since you are using Apache2 Server, so you can achieve this very easily by creating a Virtual Host.
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/vchost1.com.conf
Create Virtual Configuration using the above command, it copies the complete code of content from the default file provided by the apache2 Server.
sudo nano /etc/apache2/sites-available/vchost1.com.conf
start configuring host & domain according to your requirements
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/domain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
here also, you can multiple Virtual Host configurations in a single file, start configuring and enjoy hacking.
you can also multiple web applications in a single instance by using the same method and theis reference.
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-18-04-quickstart

multiple domains, multiple django projects, one server

Hi I'm new to apache and mod_wsgi and am trying to figure out how to configure both so that i can have www.example1.com use djangoproject1 and www.example2.com use djangoproject2.
I followed this tutorial to hook up example1.com to djangoproject1 and it works beautifully, but the tutorial doesn't exactly give the most detailed explanations for what is going on and why i need to do certain things.
what i have so far:
1) a dns zone for example2.com pointing to the server ip
2) installed python environment and django and started a new django project for djangoproject2 per the instuctions on the tutorial
I'm pretty sure i'm going to have to create a new wsgi config file and add a site configuration in /etc/apache2/sites-available/ called example2.com and then enable it, but i'm not sure about what else i'd need to do.
You can have 2 virtual hosts in your apache configuration.
The first virtual host on (default) - port 80
second one on port 81
In the virtual host, you can specify it this way:
NameVirtualHost *:80
<VirtualHost *.80>
DocumentRoot django_project_1_path
.... other config
WSGIScriptAlias / path_to_wsgi_config_1
</VirtualHost>
NameVirtualHost *:81
<VirtualHost *.81>
DocumentRoot django_project_2_path
.... other config
WSGIScriptAlias / path_to_wsgi_config_2
</VirtualHost>

How to configure Apache httpd to set multi-site for multi-user?

I have a system CentOS with Django and MySQL.
/home/user1/
-/vhost/*.conf
-/webapps/
abc.com
xyz.com
/home/user2/
-/vhost/*.conf
-/webapps/
123.com
789.com
Thanks for help!
UPDATE 1:
In httpd.conf:
User user1
Group apache
And httpd cannot access /home/user2/webapps.
You'll want to read up on Apache Vhost Configuration.
Tell us what you tried, what is working, what is not working, or what you don't understand.
Most common configuration
If your system has 1 IP address for all sites, you're going to want something like this:
#This is your 'default' host,
#people accessing the site via IP-address will see this site.
<VirtualHost *:80>
ServerName abc.com
ServerAlias xyz.com
DocumentRoot /home/user1/webapps/
</VirtualHost>
#This is the 123 and 789 vhost
<VirtualHost *:80>
ServerName 123.com
ServerAlias 789.com
DocumentRoot /home/user2/webapps/
</VirtualHost>
You can add all directives as explained by the <VirtualHost> Directive
EDIT: Updated question
There is a module called
perchild for apache that allows
to run different threads under
different users, configurable by
vhost. The module is not considered
functional, and not under current
development. Unless you know what
you're doing or are willing to take
the risk, you probably shouldn't use
it.
Another solution might be mpm-itk,
which appears to be more reliable.
Read this serverfault question
for more information, or visit their
homepage.
If you don't want to use either of both modules, you could always create a new user and group, run both vhosts under that user, and make both homedirs readable to the user by setting their group to the new group.