Configuring apache 2 virtual host - akamai problem - apache

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

Related

How do I configure apache for subdomains on pi in my own local network?

I want to access multiple websites at home on my pi apache server, like this:
projectA.localhost
projectB.localhost
or :
projectA.192.168.0.24 - IP of my pi.
I have tried to add vhost, but nothing has changed.
I can redirect my /var/www/ to other places but i want have a structur like:
/var/www/websites/projectA
/var/www/websites/projectB
I do this by modifying the hosts file on machines on my LAN that will access the server. That way, there is no special magic that has to occur in Apache (meaning that the web site can be moved to a public host without re-configuration.)
For example, configure Apache as typical with virtual hosts projecta.com and projectb.com (or projecta.localhost and projectb.localhost, if you prefer). There is no special Apache configuration on the server.
On the systems that will access projecta and projectb, configure the hosts file to point to the server's IP address:
projecta.com 192.168.0.24
projectb.com 192.168.0.24
-or-
projecta.localhost 192.168.0.24
projectb.localhost 192.168.0.24
Apache will properly route requests to the appropriate site.

how do my web server know the domain is mine?

I bought a domain and registered it on a dns server. But I wonder how my web server know whether the coming request is from my domain. E.g. someone registered his domain on my server too. Obviously apache should reject other domain's request. I just wanna know more details about how a web server (like apache) detect this. Does it simply set in the config file (maybe ServerName?) and do some string comparison?
Short answer: By default, if another person points their domain to your website, by default the webpages that are sent to their computer are the same webpages you use for www.yourdomain.com. You can also program your webserver to deny/redirect requests from other domains.
Long answer (I recommand you read):
A common newbie misconception is that domains are "TIED" to a web server. However, that is not true. They are completely different and somewhat unrelated. A domain is just shorthand for an IP address that correlates to your web server. An IP address is really what is TIED with your web server.
For example:
www.example.com could 'resolve'/correlate to 1.1.1.1
and
www.randomdomain.com could also resolve to 1.1.1.1
If 1.1.1.1 is the ip address your web server is correlated to, THEN these requests will both get sent to your web server.
Now, if you think about it, with this logic, you should be able to access your web server by just typing in 1.1.1.1 That is true!
Real world example:
www.google.com goes to Google
172.217.6.78 also goes to Google because 172.217.6.78 is one of the web servers google.com will correlate/resolve to. Go ahead and type 172.217.6.78 into your web browser. It will take you to google.com.
DNS servers point your domain to the IP address of your web server.
On your webserver:
Your server will run a software that will respond to requests it gets from the outside internet. This software will usually know how to respond to this requests using the correct syntax and also be able to handle multiple requests at the same time. When this software gets a request, it will load a file (that you specify) and send it to the user/client.
Common examples of this software include Apache (most famous/popular - runs like 40% of all websites you browse including facebook.com) and nginx (becoming more popular).
The default config of an Apache/nginx/etc web server is to serve that user (at port 80) the documents that are in the 'www' folder. However, (for Apache) if you would like to serve multiple domains on one web server (www.example.com & login.example.com), you would usually create virtual hosts. Creating virtual hosts can be done by editing your Apache configuration file. (If you're hosting on GoDaddy/namecheap or something similar, you won't have access to this.)
An example of a basic virtual host could be:
<VirtualHost *:80> #80 for port 80 - the standard port for unencrypted web traffic
ServerName www.yourdomain.com
DocumentRoot /where/your/web/files/are/located
<VirtualHost>
You could then create another virtual host to reject/forward another domain's traffic
<VirtualHost *:80>
ServerName www.randomotherdomain.com
#here, you could either serve new content to this domain using "DocumentRoot" or you can forward all traffic to your website
Redirect / http://www.yourdomain.com
<VirtualHost>
However, by default, if another person points their domain to your website, by default the webpages that are sent to their computer are the same webpages you use for www.yourdomain.com

Reverse Proxy using DDNS

As my home network grows, I am finding that I would like to get more access from the outside world and it seems this requires me to grow beyond port forwarding in my router. I have several systems (mostly virtualized) that use ports 80 and 443 (mostly) and I cannot forward those ports to multiple IP addresses. This is where I planned to use Reverse Proxy.
I am testing this on an Ubuntu 12.04 LTS system running Apache2. I have created a file called reverseprox in /etc/apache2/sites-available as follows:
root#server:/etc/apache2# cat sites-available/reverseprox
<VirtualHost *:80>
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
ServerName ws.myDomain.asuscomm.com
ServerAlias ws
ProxyRequests Off
ProxyPass / http://192.168.1.64:80/
ProxyPassReverse / http://192.168.1.64:80/
</VirtualHost>
I followed the tutorial from here:
http://www.linuxjournal.com/content/protect-your-ports-reverse-proxy?page=0,1
My web server is on 192.168.1.64 on my local network. I have an Asus router and am using Asus DDNS service setup as myDomain.asuscomm.com. I have also setup all the sym-links as required for Apache to find the necessary modules and get no errors when I restart the apache2 service (except for complaints about the loopback address in the 000-default file). I have forwarded port 80 in my router to the system running apache (on 192.168.1.62) and can see the blank "It Works!" web page so it is clear that myDomain.asuscomm.com:80 is getting to 192.168.1.62 but my VirtualHost doesnt seem to do anything when i enter ws.myDomain.asuscomm.com.
Am I missing something? Is it the fact that I am using the Asus DDNS service and myDomain.asuscomm.com is not a valid domain name? I have no problem registering a domain name to get this to work if needed. I plan to expand this to my other systems, like nas.myDomain.asuscomm.com, vSphere.myDomain.asuscomm.com, etc...
I appreciate the help!
I figured this out. I was never able to use the DDNS name directly. The solution was to pay some $$$ and register a domain name. I used NameCheap.com and registered a domain name with premium DNS service and privacy protection for $15/year.
Then, I created CNAME records of my desired URL's and set the targets to be my DDNS URL. Once the DNS servers were updated with the new CNAME records (took about 15 min), bingo! Reverse proxy works!
For example, I registered myDomain.com. In my NameCheap account settings under advanced DNS options (should be the same concept with other domain register services like GoDaddy), I defined a CNAME record with Host set to ws.myDomain.com and with a Target set to myDomain.asuscomm.com.
Now ws.myDomain.com gets defined in the DNS and resolves to my Asus DDNS address. From there it gets forwarded to my Proxy server on 192.168.1.62 and directed to 192.168.1.64:80 by means of the VirtualHost definition. And with additional CNAME record definitions for other hosts, you can define additional VirtualHosts in the Proxy server to access other machines and resources. Neat!
Cheers!

Allow only specific domains

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.

CNAME address in apache configuration

I have MULTIPLE domain to map my server's subdomain. For example
www.xyz.com -> goo.myserverdomain.com
www.lmn.com -> fb.myserverdomain.com
www.abc.com -> twt.myserverdomain.com
I do the mapping using CNAME in each domain. Now at my server end, I want to resolve my server subdomain. So i want to configure like
ServerName myserverdomain.com
ServerAlias *.myserverdomain.com
ProxyPass / http://<IP>:8780/(goo/fb/twt ...)
When I do the configuration, apache do not recognize the virtual host and show the first default one. I seems that i am getting host name. How to resolve myserverdomain address in my configuration. Please help
It does not matter how the domain mapping is done. Apache does not know this and also the web browser does not care. It simply reacts on the line "Host:" send in header.
To enable virtual name solving, you need to set
NameVirtualHost ...
for each IP+port combination or with '*' for all.
Usually when starting, Apache will tell you that you have virtual hosts, but no proper name switching.