I've been trying to get my head around this all night with no success no matter how many tutorials and resources I've looked through.
My aim is to be able to go to two different websites on the one running apache server.
End goal is something like this(using local ip);
192.168.1.8/site1 -> first site
192.168.1.8/site2 -> second site
I have included the following in my httpd.conf
<VirtualHost *:80>
DocumentRoot "/root/sites/site1"
ServerName site1
</VirtualHost>
<VirtualHost *:80>
ServerName site2
DocumentRoot "/root/sites/site2"
</VirtualHost>
Its worth mentioning that the default DocumentRoot and Directory settings are still in the http.conf and actually point to the site1 files.
Going to 192.168.1.8 takes me to site1 (guessing from the DocumentRoot settings in the http.conf)
Going to /site1 or /site2 both give me a 404 Not Found
I've run -S to see any problems but it looks good as far as I can tell;
VirtualHost configuration:
*:80 is a NameVirtualHost
default server site1 (/usr/local/etc/apache24/httpd.conf:244)
port 80 namevhost site1 (/usr/local/etc/apache24/httpd.conf:244)
port 80 namevhost site2 (/usr/local/etc/apache24/httpd.conf:248)
ServerRoot: "/usr/local"
Main DocumentRoot: "/usr/local/www/apache24/data"
Main ErrorLog: "/var/log/httpd-error.log"
Mutex default: dir="/var/run/" mechanism=default
Mutex mpm-accept: using_defaults
PidFile: "/var/run/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www" id=80
Group: name="www" id=80
Can anyone spot anything obvious that I have missed?
NameVirtualHosts are intended to be accessed by name, not by IP address. With your configuration, you've told Apache to listen for incoming connections to the hostnames "site1.example.com" and "site2.example.com" (substitute your own domain for "example.com")
Without a name to distinguish them, you can't have two virtual hosts listening to the same IP address and same port. When you go to http://192.168.1.8 , Apache has no way of knowing whether you're intending to reach site1 or site2. So it sends you to the first host that matches, which is the first <VirtualHost *:80> in your configuration. Then it takes your request for /site1 and appends that to the DocumentRoot of the first VirtualHost. But since you don't have a /root/sites/site1/site1 directory, you get a 404 error.
There are a couple of alternatives.
You could run the two VirtualHosts on two different ports.
<VirtualHost *:80>
DocumentRoot "/root/sites/site1"
...
</VirtualHost>
<VirtualHost *:8080>
DocumentRoot "/root/sites/site2"
...
</VirtualHost>
Or, you could simply have a single site with a single document root:
DocumentRoot "/root/sites"
and then just structure your filesystem so that content for site1 goes under /root/sites/site1 and site2 under /root/sites/site2. Then the URLS http://192.168.1.8/site1 and http://192.168.1.8/site2 will work automatically.
You might also be able to do make some mod_rewrite rules, but that would start to get more complex.
Related
I have tried but nothing seems to work for me here. I have an Apache server with multiple domains set up. Currently they all point to the root folder (C:\xampp\htdocs) but I'd like to organize things a little better here on. I'd like to use Apache's VirtualHost to point each new domain to a subfolder inside this folder but have all older websites point to C:\xampp\htdocs in the mean time until I can migrate each.
The issue is that when I use the following code, all my domains point to the subfolder
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\newdomain\"
ServerName www.newdomain.com
</VirtualHost>
I need to add a Virtual that listens to all other domains and points them to C:\xampp\htdocs
But I'm running out of ideas. Please help
Try that:
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs"
ServerName _default_
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:\xampp\htdocs\newdomain"
ServerName www.newdomain.com
</VirtualHost>
You need a default virtualhost, that's the catch_all thing, when the Host Header defined in the HTTP query does not match any ServerName directive the default VH is useD. And the default VH is the first one defined in the configuration.
I have a unix system whose actual name is "ech-10.45.25.12"
i have installed apache server in it.
Now i need to configure it in such a way that the two applications running in the same machine in tomcat in two different ports should be accessed by the same domain.
ie., i have two applications running in the same machine under different port
http://ech-10.45.25.12:8080/issuetracker/
http://ech-10.45.25.12:8180/dashboard/
I would like to name this server(ech-10.45.25.12) as devjunior.mycompany.com
The following is the configuration i have made in httpd.conf
Listen 80
Listen 8080
Listen 8180
NameVirtualHost ech-10.45.25.12:80
NameVirtualHost ech-10.45.25.12:8080
NameVirtualHost ech-10.45.25.12:8180
<VirtualHost ech-10.45.25.12:80>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost ech-10.45.25.12:8080>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost ech-10.45.25.12:8180>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-8080
</VirtualHost>
i know i am doing a major mistake
But i should be able to access the applications by using the following urls
http://devjunior.mycompany.com/issuetracker
http://devjunior.mycompany.com/dashboard
Should i create ANY directories under any folders any where in the system
Please tell that also.
You configured only the names. So you've configured Apache to listen for:
http://devjunior.mycompany.com:8080
http://devjunior.mycompany.com:8180
You can:
Configure 2 domains with namevirtualhost without using ports. this is the most elegant way of doing what you want
Configure a single domain that points to a single directory on the filesystem with 2 links for the diferrent applications. This works with php mostly or pure html pages. With more complex applications you could incur in a lot of headache..
Domain and port. Like you've done. But you can access only by http://devjunior.mycompany.com:8080/issuetracker and http://devjunior.mycompany.com:8180/dashboard
Solution 1
You can use different domains or subdomains (which are cookie friendly in an eventuality of single sign on).
Listen 80
NameVirtualHost ech-10.45.25.12:80
<VirtualHost ech-10.45.25.12:80>
ServerName devjunior.mycompany.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost ech-10.45.25.12:80>
ServerName dashboard.devjunior.mycompany.com
DocumentRoot /www/domain-8080
</VirtualHost>
<VirtualHost ech-10.45.25.12:80>
ServerName issuetracker.devjunior.mycompany.com
DocumentRoot /www/domain-8180
</VirtualHost>
Solution 2 is left as an excercise for the reader... :P
Here is what i did to make it work.
Though the change of name in etc/hosts file did nothing in my intranet, so i used the actual name of the machine which is ech-10.45.25.12
NameVirtualHost ech-10.45.25.12:80
<VirtualHost ech-10.45.25.12:80>
ServerName ech-10.45.25.12
ProxyPreserveHost on
ProxyPass /issuetracker http://ech-10.45.25.12:8080/issuetracker
ProxyPass /dashboard http://ech-10.45.25.12:8180/dashboard
</VirtualHost>
Also dont forget to add the "proxyName" & "proxyPort" attribute to the tag in tomcat's server.xml
I'm having some problems with setting up a VirtualHost with Apache on CentOS. I'll try my best to explain what happens.
In our httpd.conf file we had to change the Document root, our base is /var/www/mydomain.com but our files is on /var/www/mydomain.com/store2 and when users goto mydomain.com we want them to come directly to mydomain.com/store2
Main config:
DocumentRoot "/var/www/mydomain.com/store2/"
Directory "/var/www/mydomain.com/store2"
So, I've added an config file inside conf.d named subdomains.conf and this is the information inside
<VirtualHost *:80>
ServerAdmin mail#me.com
DocumentRoot /var/www/mydomain.com/subdomain
ServerName subdomain.mydomain.com
ErrorLog logs/subdomain.mydomain.com
CustomLog logs/subdomain.mydomain.com common
</VirtualHost>
When i restart the httpd service and goto mydomain.com I'm transferred to the virtual host root (/var/www/mydomain.com/subdomain) this also happens when i go to subdomain.mydomain.com. Is there something that I'm missing here? Could there be something with the DNS also? I see that mydomain.com and subdomain.mydomain.com points to the same IP-address.
I am trying to host two websites using Apache from the same Ubuntu server. I have one ip address, and I only have one domain (which resolves to the ip address). So I want requests to the domain name to give one website, and requests to the ip address to give the other.
I have symlinks in /etc/apache2/sites-enabled to two files, pointing to the config for my two sites.
One contains:
<VirtualHost 1.2.3.4:80>
ServerName 1.2.3.4
stuff
</VirtualHost>
while the other contains
<VirtualHost domain.net:80>
ServerName domain.net
stuff
</VirtualHost>
However, when I start Apache, I get the following message:
[warn] VirtualHost 1.2.3.4:80 overlaps with VirtualHost domain.net:80, the first has precedence, perhaps you need a NameVirtualHost directive
and when I point my browser at either domain.net or 1.2.3.4 I get the site that I want associated with the ip address.
If I delete either symlink, then pointing a browser at either the domain name or the ip address gives the only enabled website. (As you would hope.)
As I understand it, both config files in sites-enabled are being loaded at once, and the one containing the ip address trumps the one containing the domain name. The warning suggests looking at the NameVirtualHost directive, but all the help I can find online refers to cases where you have two domain names pointing to the same ip address.
As always, and help or advice would be much appreciated.
(For what it's worth, the websites are both Rails applications, and I'm deploying using Passenger, but I don't think that's important here.)
This is how I do it:
NameVirtualHost 1.2.3.4:80
<VirtualHost 1.2.3.4:80>
ServerName localhost
DocumentRoot /var/www/default
</VirtualHost>
<VirtualHost 1.2.3.4:80>
ServerName mydomain.net
DocumentRoot /var/www/mydomain
</VirtualHost>
Apache looks for a suitable virtualhost for every request. If it doesn't find one that matches the ServerName or any of the ServerAliases then it takes the first one. It doesn't really matter what you use for the ServerName in the first VirtualHost as it will always be used if none of the other VirtualHosts match.
Had this problem, here is what I did:
Edit httpd.conf
sudo vi /etc/apache2/httpd.conf
Add this line
NameVirtualHost *:80
NOTE: You can replace *:80 with your_ip_address:80
Now create the domain name config file. I use the domain_name.com
sudo vi /etc/apache2/sites-available/domain.com
Add this to the file
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /var/www/domain.com/public_html/
ErrorLog /var/www/domain.com/logs/error.log
CustomLog /var/www/domain.com/logs/access.log combined
</VirtualHost>
Make sure the directories in the domain.com config exists
/var/www/domain.com/public_html/
/var/www/domain.com/logs
NOTE: use the mkdir command like this if needed
sudo mkdir /var/www/domain.com/public_html/
sudo mkdir /var/www/domain.com/logs
Now we need to enable the new config file like this
sudo a2ensite domain.com
You should see a notice to restart apache, use this command
/etc/init.d/apache2 restart
Now we need a test file to view
sudo vi /var/www/domain.com/public_html/index.html
Add some text
Hello domain.com
Open your web browser and go to your new domain
http://domain.com
Make sure you have the instruction
NameVirtualHost *:80
in /etc/apache2/ports.conf
I open up a port, let's say port 81 to listen to incoming requests.
If the incoming request is www.myexample.com, then I want to redirect it to
C:\myexamplemain
folder.
If the incoming request is blog.myexample.com, then I want to redirect it to
C:\myexampleblog
folder.
Given that there are a lot of redirection rules for www.myexample.com and blog.myexample.com, I have to create a separate VirtualHost files for these two. So I need a separate configuration files that resolves the DocumentRoot. How to best do this?
The best way to do this is via virtual hosts.
NameVirtualHost *:81
<VirtualHost *:81>
DocumentRoot C:\myexamplemain
ServerName www.myexample.com
</VirtualHost>
<VirtualHost *:81>
DocumentRoot C:\myexampleblog
ServerName blog.myexample.com
</VirtualHost>
What file these are in doesn't matter. Apache processes its configuration as if it was all in one file. You can put one bit in one file and the other virtual host bit in another file and it's OK.