O
O
Oleg Pravdin2019-07-07 23:38:49
Apache HTTP Server
Oleg Pravdin, 2019-07-07 23:38:49

How to set VirtualHost in Apache2 which will be used if there is no matching ServerName?

Actually, subject. There is a task to deny access to the site by server IP, the solution of which I implemented through the 0000-direct.conf file with the following content:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName IP_моего_сервера
    Redirect 403 /
    DocumentRoot /dev/null
</VirtualHost>
</IfModule>
<VirtualHost *:80>
    ServerName IP_моего_сервера
    Redirect 403 /
    DocumentRoot /dev/null
</VirtualHost>

I would like to expand the solution: if there is no VirtualHost with ServerName satisfying the request, then a 403 error would be thrown (as in the example above). How can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CityCat4, 2019-07-08
@CityCat4

Usually, the config is written based on the following Apache behavior - if there are no hosts that satisfy the condition, then show the first available host.
Accordingly, the first thing in the config is to specify the host on which the stub will be.

A
Andrey Ezhgurov, 2017-10-06
@waspmax1

From the set of rows of the first table, we subtract the set of rows of the second table and write the result into the third table. In MySQL this is done with a single INSERT ... SELECT SQL statement. But since SQL-command EXCEPT (set difference) is not implemented in MySQL, its emulation is used by the standard technique (described in any textbook) through LEFT JOIN and IS NULL:

INSERT INTO table3
SELECT table1.*
FROM table1
LEFT JOIN table2
  ON table1.id = table2.id
WHERE table2.id IS NULL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question