Allow only specific domains - apache

I have an apache 2.4 server with some virtual hosts, let's say I have aaa.com domain and a few subdomains, bb.aaa.com and cc.aaa.com, currently I want apache server to listen only aaa.com and bb.aaa.com and ignore cc.aaa.com or just redirect cc.aaa.com to aaa.com (btw I have no virtual host for cc.aaa.com).
So my objective would be to allow connections only from aaa.com and bb.aaa.com, any other connection (from direct IP or any other subdomain not handled by virtual hosts) should be redirected to aaa.com or just refused.
I did not found any solution for this, actually I am not even sure if it's possible.

If you don't have a virtual host for cc.aaa.com and if this domain is pointing to your server then by default apache will enter into the first virtual host. So you might want to set the redirect here.

Related

Port forward port 80 to diff websites depending on sub-domain wherein contents reside in diff machines

In the coming months I'll be creating different websites. Actually, one has been up already for awhile but I shut it down because of internet issues.
My issue now is I want to create another website but just under a certain sub-domain. I want to do this so that I can maximize my domain. So I'll be creating say:
1. www.example.com
2. api.example.com
3. xyz.example.com
My home router forwards port 80 to a certain local IP 192.168.0.3 which is a virtual machine. I want to make contents of different websites to reside in different VMs to avoid conflicts. So those 3 websites, are in different VMs.
Now, how can I set my router to target a VM depending on the website being requested provided that my router only targets one IP to port forward port 80?
Am I correct that I'll be using reverse proxy of Apache2?
Update: Is this an ideal solution on websites with this setup? If not how is large corporations set it up?
first you have to configure the dns server of your domain to forward all domains to the same ip address (use some a A-Records)
a-record
and then configure Name-based virtual hosts in the configuration of your apache webserver.
Name-based virtual hosts
in this Virtual hosts you can forward to the VMs

Direct incoming port 80 traffic to local virtual host

I am running MAMP Pro on a Mac and I have port forwarding set up on my router to forward traffic to my server. For now I just have an IP for my computer, no domain name or DNS setup, although I could do that. What I want to do is forward incoming traffic to a particular virtual host on my server. e.g. MAMP has a localhost by default. I have a number of other virtual hosts, xxxx.local, and I would like to forward to a particular one. Can I do that by editing httpd.config or the hosts file.
Apache "sees" the "host name" of the incoming request and forwards it to the virtual host with the same same. All other requests are captured from "localhost".
It's called "single link multihoming",means one IP address for a lot of virtual hosts.
Greetings,
Peter
I actually just pointed one of my domains to my home server IP and that works since it has a domain name and I have a local virtual host setup. My original question was whether it is possible to do something like that if you just have an IP (i.e. can you send all requests to an IP to a particular single local virtual host rather than to the default localhost), and I guess the simple answer is no. It forwards those to the localhost.

Access virtual host on apache without host redirection?

I have apache 2.4 installed on Ubuntu server 14.04 and have setup different virtual host like domain1.com,domain2.com,domain3.com. The web server is meant to be accessed only from local network. So I tried to edit /windows/syste32/drivers/hosts and added line like this
192.168.1.90 domain1.com
and can now access the domain1 from that machine by simply putting domain1.com in browser. However I wonder if I can access specific virtual host on apache without editing the hosts file, I mean entering something like this in browser
192.168.1.90/domain1.com
, but this doesn't work since apache tries to retrieve content from the default host. In other words: If I know the apache server ip and virtual host domain, can I access it via browser directly?

Configuring apache 2 virtual host - akamai problem

Normally I have no problems setting up Apache2 virtual hosts. However, in this case the domain is configured via Akamai rather than the normal DNS record, and apache is displaying the default site rather than the one I have configured for the required subdomain.
In other words, I have configured a virtual host test.domain.com, but Apache is displaying the default one when I go to http://test.domain.com/, and I guessing this is because Apache is not receiving the request from test.domain.com but from something else on the Akamai network.
How do I find out what the correct configuration of the virtual host should be?
Your main domain (in this case test.domain.com) needs to be configured as a CNAME to the akamai network (test.domain.com.edgesuite.net), and then you need an origin hostname such as origin-test.domain.com. Then you need to create an "Edge Hostname" on the akamai network portal and then a configuration on the HTTP network to answer for that digital property (test.domain.com). Akamai can be configured to forward the requesting domain (test.domain.com) or the origin forward domain in the Host header (origin-test.domain.com). either way you should setup your Apache Virtualhost to answer for both by doing
ServerName test.domain.com
ServerAlias origin-test.domain.com

Multisite installation, each website should have different IP

I have 17 sites with a multisite installation and uses the domain access module. This means that I have the same code base and same database for all 17 sites.Is it possible to configure Apache(hosting server) in such a way that all sites have a different IP even if the physical location for all sites is same?
Sure, if your server is set up to accept traffic for each IP, you just need to use IP-based VirtualHosts instead of name-based VirtualHosts.
Namely, you'll need to have Apache Listen directive for each IP address in apache.conf, and each VirtualHost block would have to reference the IP address its listening on.
More info:
Creating Name and IP Based Virtual hosts in debian (it's not really just for Debian)
Name-based hosts on more than one IP address (VirtualHost Examples)