Nginx sets unbound domain name to prohibit access

不言
Release: 2023-04-02 20:32:02
Original
2200 people have browsed it

This article mainly introduces the setting of Nginx to prohibit access to unbound domain names. It has certain reference value. Now I share it with you. Friends in need can refer to it.

By default, Nginx allows direct access. You can directly access the website through IP, or access it through an unset domain name (for example, someone points his own domain name to your server IP). This easily exposes some websites on the server, so how do we set Nginx to prohibit these behaviors?
server {
    listen 80 default_server;
    server_name _;
    return 404;
}
Copy after login

When the unbound domain name points to your server, if it cannot match the virtual host domain name you configured, this virtual host will be used by default, and then 404 will be returned directly.

listen 80 default_server: Specify the server configuration section as the default host of port 80. That is, when the unbound domain name points to your server, it cannot match the virtual host domain name you configured. After that, this virtual host will be used by default.

server_name _: _ here can be replaced with any other invalid characters or invalid domain name, which means that the server configuration will not be accessed normally.

return 404: means returning 404 error directly.

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to add modules to Nginx

nginx implements reverse proxy and load balancing

The above is the detailed content of Nginx sets unbound domain name to prohibit access. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!