A
A
Andrey2017-07-10 15:08:22
Apache HTTP Server
Andrey, 2017-07-10 15:08:22

Apache 2.4, can't set up name-based VirtualHost on localhost. Why 400 error?

Dear experts - I ask for help.
There is a computer under Windows 7. You need a local server on it. I used to use XAMPP, but it stopped suiting me.
I decided to install Apache2.4+PHP+mySQL separately. There were no particular problems.
But for the second day I can not configure name-based VirtualHost. those. it is necessary that at the addresses localhost, captcha_lite and, if necessary, other names - different sites open. On XAMPP it worked.
How I set it up on Apache:
Uncommented these lines in the httpd.conf file

LoadModule vhost_alias_module modules/mod_vhost_alias.so

Include conf/extra/httpd-vhosts.conf

in the file httpd-vhost.conf wrote the following
<VirtualHost *:80>
    DocumentRoot "D:/USR/www"
    ServerName localhost
  ServerAlias www.localhost
    ErrorLog "D:/USR/log/localhost/error.log"
    CustomLog "D:/USR/log/localhost/access.log" common
  ServerAdmin [email protected]
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "D:/USR/www/captcha_lite"
    ServerName captcha_lite
  ServerAlias www.captcha_lite
    ErrorLog "D:/USR/log/captcha_lite/error.log"
    CustomLog "D:/USR/log/captcha_lite/access.log" common
  ServerAdmin [email protected]_lite
</VirtualHost>

Naturally made the appropriate entries in the hosts
But nothing works!
When visiting localhost, what opens is what should open, but this only happens because it is listed first in httpd-vhost.conf and is used by default in all situations. For example, the same thing opens if you go to s1.localhost (also registered in hosts at the same address).
If you go to captcha_lite, it gives an error 400. And a page with one line for the test should open.
Bad Request

Your browser sent a request that this server could not understand.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

The problem is this:
How everything should work, according to the description
With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. Using this technique, many different hosts can share the same IP address.

When a request arrives, the server will find the best (most specific) matching argument based on the IP address and port used by the request. If there is more than one virtual host containing this best-match address and port combination, Apache will further compare the ServerName and ServerAlias ​​directives to the server name present in the request.

The browser does everything right - there is Host "captcha_lite" in the headers. And the server sends a 400 error in response.
WHY? As if I just set something up wrong, but what? I've already rummaged all over Google. Help me please.
The most interesting thing is that when you add this to httpd-vhosts.conf:
<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "D:/USR/www/s1.localhost"
    ServerName s1.localhost
    ErrorLog "D:/USR/log/s1.localhost/error.log"
    CustomLog "D:/USR/log/s1.localhost/access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "D:/USR/www/s2.localhost"
    ServerName s2.localhost
    ErrorLog "D:/USR/log/s2.localhost/error.log"
    CustomLog "D:/USR/log/s2.localhost/access.log" common
</VirtualHost>

at s1.localhost , what is needed is opened, and at s2.localhost , what should be opened at captcha_lite is opened.
if you leave only these entries there, everything generally works as it should, but only for them.
How to make captcha_lite work?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
DmStrelok, 2018-04-23
@DmStrelok

Try creating the path manually: D:/USR/log/s1.localhost/
I also had problems with apache because of a non-existent path.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question