apache2 virtualHost Name-based hosts on more than one IP address - apache2

is it possible when people access example.namedomain.com will go to documentRoot /var/www/html (192.168.10.8)
but when typing the address example.namedomain.com/test
then it will go to documentRoot /var/www/html/test on a different other local server (192.168.10.9)?

Related

What is the meaning of star in <VirtualHost *:80> in apache?

I want to know the use of this * and how to configure it?
* means a wildcard when you use wildcard you do bifurcation on ServerName
<VirtualHost *:80>
DocumentRoot /var/www/app1
ServerName app1.example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/example
ServerName example.com
</VirtualHost>
Apache will route example.com to /var/www/example where as app1.example.com would be routed to /var/www/app1
VirtualHost directive allows you to configure and use multiple sites located on the same IP address. In this case, with *:80 you are creating a virtual host for every request coming on the port 80. It becomes more interesting when you start specializing and start to insert something other than * in the virtual host. An example can be, that according to the IP address with which a port is hit, you can open a different version of a web site, perhaps with different resources like: language translations, styles etc.

configurations for the Subdomain module in drupal 7

What are the appropriate configurations for the Subdomain module in drupal 7 on Window 7 running XAMPP?
My site is localhost/example
Here are the changes I have made:
settings.php
$cookie_domain = '';
Leaving this commented out gives me an error
"The $cookie_domain variable in settings.php is not set".
Uncommenting and putting in "localhost", ".localhost", "example", ".example" gives me an "Access denied" error.
It seems to accept "localhost/example" or a blank ' ', although I don't know if this is the right thing to do.
host
127.0.1.1 localhost example
(and I can successfully ping ideastar)
http.conf
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example
ServerAlias *.example
DocumentRoot C:/xampp/htdocs
</VirtualHost>
getting the fallowing error
Subdomain error: localhost and subdomain-test.localhost did not resolve to the same IP address. Your DNS may be improperly configured and subdomains will likely not work.
First you should create two virtual host one for main domain and another for sub-domain. For ex: like we have two domains example.com and test.example.com to setup on local host. I am assuming that you have a fresh install of Xampp on your machine. Your virtual host [\xampp\apache\conf\extra\httpd-vhosts.conf] file should have these entries:
<VirtualHost *:80>
DocumentRoot "\xampp\htdocs\example"
ServerName example.com
ServerAlias example.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "\xampp\htdocs\example"
ServerName test.example.com
ServerAlias test.example.com
</VirtualHost>
Now open you system host file and make the following entries below the line "127.0.1.1 localhost" (localhost ip 127.0.0.1)
127.0.1.1 example.com
127.0.1.1 test.example.com
\xampp\htdocs\example this directory should contain your Drupal setup.
Cookie domain entry should be as per the below line
$cookie_domain = '.example.com';
i have assumed that you already have a Drupal site running at http:\localhost\example.

Can't access my website through ip. Is something wrong with my httpd settings?

I just set up a fresh apache/mysql install on CentOS on remote server.
Right now I just want to be able to access my server through ip on my server
let's say the ip is 64.123.myip.whatever
Here is my /etc/httpd/conf/httpd.conf setting
### Section 2: 'Main' server configuration
ServerName 64.123.myip.whatever:80
### Section 3: Virtual Hosts
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.example.com
DocumentRoot /var/www/html
ServerName 64.123.myip.whatever
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>
I restart my apache, try to access this server and I get this error in the browser
Oops! Google Chrome could not connect to 64.123.myip.whatever
Why doesn't this work?
A couple of things. First... do you literally mean IP address? If so then putting that into Chrome is going to actually go right to that address. The odds of that random IP address actually hosting a webserver is fairly remote, hence the error. ServerName cannot be an IP address. If you instead mean you're trying to use a ServerName of "64.123.myip.whatever", then you must add a host entry that directs all traffic for "64.123.myip.whatever" to the IP address of your web server (presumably 127.0.0.1).

Hosting multiple sites with Apache2

I have on a server machine a local domain called "localwiki.com" that points to /var/www/wiki and works fine.
The sites-available and sites-enable configuration:
<VirtualHost *:80>
DocumentRoot /var/www/wiki/
ServerName localwiki.com
ServerAlias *.localwiki.com
</VirtualHost>
I wanted to create a second local domain for /var/www/doxygen (which I can access using "serverIP"/doxygen).
Here is the localdoxygen.com config file created at /etc/apache2/sites-available/localdoxygen.com
<VirtualHost *:80>
DocumentRoot /var/www/doxygen/
ServerName localdoxygen.com
ServerAlias *localdoxygen.com
</VirtualHost>
I used "a2ensite" in order to create a symbolic link in sites-enable pointing to localdoxygen.com in sites-available:
sudo a2ensite localdoxygen.com
I also have reloaded the new configuration:
sudo /etc/init.d/apache2 reload
And restarted apache:
sudo service apache2 restart
But the domain (localdoxygen.com), still doesn't work.
Any suggestions on how to fix this?
To solve the problem I had to add an entry to /etc/bind in order to activate the DNS for the domain.
I think those conf files must end in .conf to be loaded: i.e. localdoxygen.com.conf
disable the default site - a2dissite default (!!!)
DNS correct
check in /etc/apache2/sites-enabled have your sites
reload apache2 /etc/init.d/apache2 reload
You need to define a NameVirtualHost in your apache2.conf to support multiple domains under one IP.
NameVirtualHost 123.456.789.123:80
or
NameVirtualHost *:80
see also Running several name-based web sites on a single IP address.

Does Apache2 support virtual hosting of subdomains?

Currently my Apache server is set up like so
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
The problem is that everything below /var/www is accessible from everywhere else. If I have a web page /var/www/john/bio.html, then that web page could borrow scripts/pictures from var/www/jane/
I want to set up my Apache server like so
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:80>
ServerName www.john.example.com
ServerAlias john.example.com
DocumentRoot /var/www/john
</VirtualHost>
<VirtualHost *:80>
ServerName www.jane.example.com
ServerAlias jane.example.com
DocumentRoot /var/www/jane
</VirtualHost>
So all the files for user john go in the /var/www/john/ folder, and likewise for user jane. Then, with symbolic links turned off (by default), and access only provided from /var/www/user/ downwards (again by default), I don't have to worry about john's web page including scripts/images from jane's web page.
Using local measures only (/etc/hosts instead of a DNS) I found that this can indeed work.
First, change your /etc/hosts file to have a mapping of your desired website name(s) (www.example.com), and target IP address (192.168.1.1). I used my local IP address.
IPAddress Hostname Alias
----------- -------------------------- ------------------
192.168.1.1 www.example.com example.com
192.168.1.1 www.john.example.com john.example.com
192.168.1.1 www.jane.example.com jane.example.com
Your web browser will check your /etc/hosts file before looking at the world wide web.
Next go through all your Apache config files (httpd.conf, apache2.conf, ports.conf, conf.d/*) and make sure in exactly one file the command NameVirtualHost *:80 is issued (it doesn't have to be port :80 but if it is issued more than once, you will get this problem). Mine was issued in /etc/apache2/ports.conf, so put yours there if you have to. Finally, update your Apache configuration file (mine was at /etc/apache2/sites-available/default) like so.
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www
</VirtualHost>
<VirtualHost *:80>
ServerName www.john.example.com
ServerAlias john.example.com
DocumentRoot /var/www/john
</VirtualHost>
<VirtualHost *:80>
ServerName www.jane.example.com
ServerAlias jane.example.com
DocumentRoot /var/www/jane
</VirtualHost>
As a final step, you may need to add the websites to Apache by issuing the below commands (this step is not necessary, if you give all websites into sites-available/default and not into separate files for individual websites).
# a2ensite www.example.com
# a2ensite www.john.example.com
# a2ensite www.jane.example.com
After doing this, john.example.com will go to /var/www/john. That directory will then act as the root directory, and john will no longer have access to www, and, therefore, have no access to /var/www/jane.
Likewise, after doing this, jane.example.com will go to /var/www/jane. That directory will then act as the root directory, and jane will no longer have access to www, and, therefore, have no access to /var/www/john.
With symbolic links turned off --by default-- neither directories will be able to access each other

Resources