CNAME address in apache configuration - apache

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.

Related

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!

IP address is shown in address bar instead of domain

I have a WAMP home web server up and running on a static IP and registered a domain with Namecheap, but I'm a bit shaky with DNS. At first I used URL Redirect and pointed it to my IP. This meant that when you typed in the domain (like example.com) it just redirected you right to my IP, replacing the domain name with it in the address bar. Now I'm trying to get the domain to show instead of the IP in the address bar, which I'm struggling to understand exactly how to do.
The latest thing I've tried which many people say to do is instead of using URL Redirect to use the A (Address) record type and point it to my IP, which I thought would finally fix my problems. Of course after 15 min or so when it all got updated I'm getting a 400 Bad Request with nginx under it in Firefox, and a blank page in Chrome. Now I'm getting blank pages in both. Did I do something wrong here? Do I need to edit something on the web server such as httpd.conf? Am I going at this completely wrong?
Yes you should do away with the redirect and instead create an "A record". The sub-domain entry would typically be, but is not restricted to "www". The record type "A" and destination/target would be your external IP address. Once you update this record it may take several hours before you notice it taking effecting, upon where on people typing your URL would be directed to your web server.
You will need to forward port 80 on your router to the server hosting WAMP.
Finally the WAMP server should be provided with your domain name so it knows which site to load. If use the VirtualHost file this will allow you to host multiple domains on your web server. To do this...
Uncomment the following line so it appears like below in your Apache httpd.conf, to allow Apache to use virutal hosts
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Then locate the httpd-vhosts.conf file, should be found in your WAMP installation location, such as C:\wamp\bin\apache\apache*version_number*\conf\extra\
Add an entry for your site, altering the details to your own domain name and website location.
<VirtualHost *:80>
ServerName www.stackoverflow.com
ServerAlias stackoverflow.com
DocumentRoot "C:/websites/stackoverflow/"
ErrorLog "C:/websites/stackoverflow/logs/error.log"
CustomLog "C:/websites/stackoverflow/logs/access.log" common
</VirtualHost>
Now restart your WAMP server and give it a whirl.
Tip: If your server won't start after these changes, check that you have created the folder structure for the log files!
Solution described here could resolve this issue.
Most of the free dynamic dns providers, allow acquiring more than one free host name. If allowed you can solve the problem by getting a second name, e.g., mysite2.somefree.org.
Now, go and configure your free domain names in the dashboard of free provider in the following way (assume your IP is 188.165.15.29 and your server's listening to port 8085).
redirect mysite1.somefree.org to mysite2.somefree.org:8085
redirect mysite2.somefree.org to your dynamic IP, say, to 188.165.15.29
This also works when you are using Apache httpd server alone, not being part of WAMP. You do not need to tweak virtual host or any part of your server. You only configure inbound direction.
Use Forward with masking where you registered your domain. mine is GoDaddy.
in the forward settings, you will see this at bottom of the page. click Forward with masking and add the title you want them to see in the address bar of the browser when they go to your site. instead of showing your IP address

Define local site in Apache - Use port other than 80

I'm wondering if anyone can help me define a new local VirtualHost using Apache.
The goal is to have a site that is viewable only from the local network (hidden behind a firewall). Right now I have Webmin installed and it runs on transaction:10000. I am trying to get the other site running on transaction:7000.
The following does not work:
DocumentRoot /var/path
Is there a better way to do this? I'm new to Apache and trying to figure this out.
Summary: Need local /var/path directory to run on a port other than 80 for local access only.
I'm assuming that you don't know to Apache Virtual Host Code. I will show you how to use it. If this didn't help you please don't hesitate to reply to me.
You must place code in your HTTPD.CONF which can be found in the conf folder. If your file is called wwwroot instead just change the name in the code below BUT DO NOT CHANGE THE NAME OF THE FOLDER!!!
NameVirtualHost 111.22.33.44
<VirtualHost *:7000>
ServerName www.domain.tld
ServerPath /domain
DocumentRoot /htdocs/domain
</VirtualHost>
What does this mean? It means that a request for any URI beginning with "/domain" will be served from the virtual host www.domain.tld. This means that the pages can be accessed as domain.tld/domain/ for all clients, although clients sending a Host: header can also access it as domain.tld/.
In order to make this work, put a link on your primary virtual host's page to http://www.domain.tld/domain/. Then, in the virtual host's pages, be sure to use either purely relative links (e.g., "file.html" or "../icons/image.gif") or links containing the prefacing /domain/ (e.g., "http://www.domain.tld/domain/misc/file.html" or "/domain/misc/file.html").
So all domains will be pointed to your IP address and based on the domain name if it is "www.domain.tld" it will take you to the folder "/htdocs/domain" or "/wwwroot/domain"
EDIT:
<Directory "/var/path/">
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Directory>
This lets access to the "/var/path/" folder from only localhost which is where Apache is configured which is on your computer!
Good Luck!!!

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

How to setup sub-domains like blogspot

What should do to setup a sub-domain for the users when they sign-up into my site.
What are the infrastructure required? I am using Linux servers.
You can either use a specific DNS (CNAME or A/AAAA) entry for each known subdomain, or a wild-card DNS entry that'll accept *.example.com:
$ORIGIN example.com
foo IN A 12.34.6.78
bar IN A 12.34.6.78
or
$ORIGIN example.com
* IN A 12.34.6.78
The advantage of this latter is that no changes are required to either DNS or Apache configuration once the service is running. The disadvantage is that all such wildcard lookups must (by definition) end up returning the same IP address.
The Apache configuration will depend on your requirements, both for end-user control and security. Note that if the users have permission to run CGI scripts on the server then additional setup will be needed to ensure that that's done securely.
Depending on whether content is static or dynamic this will also affect your configuration:
Use mod_vhost_alias to map individual virtual hosts into their individual directories on the server.
If you really want, create a separate <VirtualHost> section for each known site, but then you'll have to restart Apache each time a new user signs up
Use a single <VirtualHost> and then look at the hostname part of the requested URL (from the $SERVER_NAME environment variable) in the scripts that render the output to figure out which user's content to display.
You can make a CNAME entry/ A Record in your DNS settings, for each subdomain
A CNAME record is a record in your
Domain Management Settings that allows
you to control a subdomain of your
domain.
To automate it along with registration, you can write a script which is executed for each user, when s/he registers.
You can refer to this link, as well, for a step-by-step process for Apache:
How to setup subdomains in apache
(since you mentioned Linux, I assume it must be APache. Please mention if it is otherwise)
Alternate Solution
You can also refer to the wildcard solution, given by Alnitak, in the same thread. I find his is an easier way. :)
infrastructure includes access the the dns server to add a wildcard entry, and rewrite rules in Apache.
Try these answers:
How to let PHP to create subdomain automatically for each user?
How to make subdomain user accounts in a webapp
or this link:
http://jam.jrox.com/docs/index.php?article=76
If your using Linux server's I'm assuming your using Apache as your webserver.
You'll have to setup proper DNS routing for the sub domain as well as a virtual host.
Virtual Hosts are fairly easy to setup but I'm not sure how easy it is to do them on the fly progmatically.
Most of the time it's as easy as editing your apache config file and adding the following:
Port 80
ServerName www.mydomain.com
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/user-bob
ServerName bob.mydomain.com
...
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/user-sally
ServerName sally.mydomain.com
...
</VirtualHost>
The VirtualHost Documention will probably of some use to you.
Apache allows you to specify any number of 'sites' based on subdomains on a single server. Creating a new 'site definition' file with the appropriate subdomain information in it, along with proper DNS wildcards, will do what you want.
In other words, the process is like this:
Setup wildcards so that *.mysite.com directs to the proper server.
When a new user signs up, create the proper Apache site definition file - you'll probably have a base template that you put the right subdomain information into and save.
Make Apache re-read its configuration.
Profit.
IMPORTANT This is based on a Debian-style Apache configuration, where the config files are included in a directory, and the main configuration reads all the config files in that directory. This will simplify things a great deal, because adding/removing subdomains will mean adding/removing files, rather than editing a single file, and so the process will be much easier to automate.