Serving two Apache sites with a single domain name and one IP address

I am trying to host two sites using Apache from the same Ubuntu server. I have one IP address and I have only one domain (which resolves the ip address). Therefore, I want domain name queries to give one website and request an ip address to give to another.

I have symbolic links in / etc / apache 2 / sites-enabled for two files indicating the configuration 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 to any domain or 1.2.3.4, I get a site that I want to associate with an IP address.

, , IP-, -. ( .)

, , , ip, , . NameVirtualHost, , , , , IP-.

, .

( , - - Rails-, Passenger, , .)

+5
3

:

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 . , ServerName ServerAliases, . , ServerName VirtualHost, , VirtualHosts .

+9

, :

httpd.conf

sudo vi /etc/apache2/httpd.conf

NameVirtualHost *:80

. *: 80 your_ip_address: 80

. domain_name.com

sudo vi /etc/apache2/sites-available/domain.com

<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>

, domain.com

/var/www/domain.com/public_html/
/var/www/domain.com/logs

: mkdir,

sudo mkdir /var/www/domain.com/public_html/
sudo mkdir /var/www/domain.com/logs

,

sudo a2ensite domain.com

apache,

/etc/init.d/apache2 restart

sudo vi /var/www/domain.com/public_html/index.html

Hello domain.com

-

http://domain.com
+4

Make sure you have instructions

NameVirtualHost *:80

in / etc / apache2 / ports.conf

0
source

All Articles