编程知识 cdmana.com

How does nginx shield access of undefined virtual hosts

Reading guide NGINX How to block access to undefined virtual hosts , Make clear  nginx  Virtual host matching rules , Then you can use the default virtual host Block undefined virtual host access

NGINX  How to block access to undefined virtual hosts NGINX  How to block access to undefined virtual hosts

nginx Default virtual host for

Nginx Support virtual hosts based on domain name and port (virtual host), According to the  $host  and  $server_port  Assign the request to the corresponding virtual host .

And if a request is resolved to webserver, But its corresponding virtual host is not configured , Will forward the request to   Default virtual host (default server).

The default virtual host can use default_server Appoint , such as :

server {
    listen      80 default_server;
    server_name example.net www.example.net;
    ...
}

 

And if you don't use a definition , Then use   The first virtual host   Rules for handling requests . For example nginx.conf The first virtual host of , Or is it conf.d Inside   Sort first   Of the configuration file   The first virtual host   Rules for handling requests .

such as , nginx.conf There is no virtual host configured in the configuration file , It's all contained in conf.d, stay conf.d There are : a.conf, b.conf, c.conf... The rules for handling requests are a.conf The first one defined in Virtual host .

Block undefined virtual host access

Make clear nginx Virtual host matching rules , Then you can block undefined virtual host access in the default virtual host .

server {
    listen      80 default_server;
    server_name "";
    return      444;
}

server {
    listen      80;
    server_name example.org www.example.org;
    ...
}

server {
    listen      80;
    server_name example.net www.example.net;
    ...
}

 

such , You can block undefined virtual host access . The main application is shielding IP Address access WebServer.Linux It's time to learn

版权声明
本文为[osc_ 3ytpwpyb]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224121944917r.html

Scroll to Top