I'm attempting to host two websites using Apache in the same Ubuntu server. I've one ip, and that i have only one domain (which resolves towards the ip). And So I want demands towards the domain title to provide one website, and demands towards the ip to own other.
I've symlinks in /etc/apache2/sites-enabled to 2 files, pointing towards the config for my two sites.
One consists of:
<VirtualHost 1.2.3.4:80>
ServerName 1.2.3.4
stuff
</VirtualHost>
as the other consists of
<VirtualHost domain.net:80>
ServerName domain.net
stuff
</VirtualHost>
However, after i start Apache, I recieve the next message:
[warn] VirtualHost 1.2.3.4:80 overlaps with VirtualHost domain.net:80, the first has precedence, perhaps you need a NameVirtualHost directive
so when I point my browser at either domain.internet or 1.2.3.4 I recieve the website which i want connected using the ip.
Basically remove either symlink, then pointing a browser at either the domain title or even the ip provides the only enabled website. (While you would hope.)
When I comprehend it, both config files in sites-enabled are now being loaded at the same time, and also the one that contains the ip trumps the main one that contains the domain title. The warning indicates searching in the NameVirtualHost directive, but all of the help I'm able to find online describes cases when you've two domains pointing towards the same ip.
Of course, and help or advice could be much appreciated.
(For which it's worth, those sites are generally Rails programs, and I am implementing using Passenger, however i don't believe that's important here.)
This is the way I actually 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 searches for a appropriate virtualhost for each request. Whether it does not locate one that suits the ServerName
or the ServerAliases
it takes the first. It does not really appear you utilize for that ServerName
within the first VirtualHost
as most commonly it is used if no other VirtualHosts
match.
Make certain you will find the instruction
NameVirtualHost *:80
in /etc/apache2/ports.conf
Had this issue, here's what Used to do:
Edit httpd.conf
sudo vi /etc/apache2/httpd.conf
Add this line
NameVirtualHost *:80
NOTE: You are able to replace *:80 with your_ip_address:80
Now produce the domain title config file. I personally use the domain_title.com
sudo vi /etc/apache2/sites-available/domain.com
Add this towards 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 certain the sites within the domain.com config is available
/var/www/domain.com/public_html/
/var/www/domain.com/logs
NOTE: make use of the mkdir command such as this as needed
sudo mkdir /var/www/domain.com/public_html/
sudo mkdir /var/www/domain.com/logs
Now we have to let the new config file such as this
sudo a2ensite domain.com
You need to visit a notice to restart apache, make use of this command
/etc/init.d/apache2 restart
Now we want an evaluation file to see
sudo vi /var/www/domain.com/public_html/index.html
Then add text
Hello domain.com
Open your internet browser and see your new domain
http://domain.com