VirtualHost files pointing to the first VirtualHost in Ubuntu 12.04

So, I installed 2 virtual host files, example1.com and example2.com with the following information:

- first file

<VirtualHost 127.0.0.1:80> ServerName example1.com ServerAlias www.example1.com ServerAdmin admin@example1.com DocumentRoot /var/www/example1.com </VirtualHost> 

- second file

 <VirtualHost 127.0.0.1:80> ServerName example2.com ServerAlias www.example2.com ServerAdmin admin@example2.com DocumentRoot /var/www/example2.com </VirtualHost> 

and configure my hosts file to read

 127.0.0.1 locahost 127.0.0.1 example1.com 127.0.0.1 example2.com 

But if I try to go to localhost, example1.com or example2.com, my browser will just send me to example1.com

default virtual host file:

 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> 

Suppose AllowOverride for / var / www takes precedence over a rule?

So, I later just turned off all my virtual hosts with a2dissite and commented out these lines in the hosts file, but half of my sites didn’t work at all.

One of my Wordpress sites didn’t seem to have pulled out its css file, so all of it was disabled (this was normal 24 hours ago), a couple of sites seemed to have lost contact with the database.

I have no idea what is happening, but everything is upset.

edit - in my original question there were both virtualhost files pointing to example1.com, which was a copy error, the actual files point to valid website URLs

+4
source share
1 answer

My best guess, not seeing more of your apache config, is that you don't have a name-based shared hosting . To do this, include the following in your Apache configuration:

 NameVirtualHost *:80 

IP-based shared hosting is the default mechanism that Apache uses without this directive.

By the way, if you do this, the <VirtualHost> argument of the blocks should match the NameVirtualHost directive, so use this instead:

 <VirtualHost *:80> 

If you are going to deal with many different sites in one window, you can take a look at the documentation for mod_vhost_alias .

+6
source

Source: https://habr.com/ru/post/1445664/


All Articles