在生产环境中,为了网站的安全访问,需要Nginx禁止一些非法访问,如恶意域名解析,直接使用IP访问网站。下面记录一些常用的配置示例:
1)禁止IP访问
如果没有匹配上server name就会找default默认,返回501错误。
server { listen 80 default_server; server_name _; return 501; }
2)通过301跳转到主页
server { listen 80 default_server; server_name _; rewrite ^(.*) http://www.jb51.com/$1 permanent; }
3)凡是请求www.jb51.com都跳转到后面域名www.yisu.com上。(需要放到server配置里)
if ($host ~ '^www.jb51.com'){ return 301 https://www.yisu.com$request_uri; }
4)Nginx限制非法域名恶意解析到本地服务器和IP访问网站
server {undefined listen 80 default_server; server_name _; return 501; }
The above is the detailed content of How to ban ip access or illegal domain name access in Nginx. For more information, please follow other related articles on the PHP Chinese website!

Nginx Monitoring Configuration File: events block: Controls connection processing, such as concurrency and multi-receive mechanisms. http block: Configure access logs, error logs, and performance-related settings. server block: Defines the virtual host, including the listening port, host name, and root directory. location block: Used for request forwarding (such as proxy and FastCGI), as well as cache configuration. Monitoring module: ngx_http_stub_status_module provides server status information, ngx_http_server_tokens_module adds server header.

To make nginx listen to port 80, you need to modify the listen instruction in the configuration file to listen 80, and check the user permissions to ensure that you have root permissions. Finally, reload nginx and verify that the listening port is correct.

Nginx can be configured to listen to the same port and forward traffic to different applications based on request: create a virtual host configuration, specify the port and server name. Use the proxy_pass directive to set the forwarding target in the location block. Start a different application and make sure it is listening for incoming connections. Test the configuration, navigate to a different server name to verify traffic forwarding.

In order for NGINX to listen to domain names without listening to ports, it is necessary to configure it in the configuration file: 1. Configure the virtual host and specify the domain name to listen to; 2. Delete the default listening port; 3. Configure DNS resolution; 4. Restart NGINX. This way, NGINX will only listen to the domain name, improve security and enable SNI.

To make Nginx listen for IPv6 addresses, configure the listen directive in the server block configuration and specify the IPv6 address as a parameter. The specific steps include: opening the Nginx configuration file, adding the server block configuration, configuring the listen instruction to specify the IPv6 address, saving the changes and restarting Nginx. If the website uses SSL/TLS, you also need to configure an SSL certificate for the IPv6 address.

At the beginning of the new year, Lei Jun shared three New Year's wishes for 2025 at the beginning of the new year, and this four and a half hours-long live broadcast attracted a lot of attention. Lei Jun’s three major wishes are: First, achieve the delivery target of 300,000 vehicles, alleviate the pressure, and no longer be caught up by progress. Second, have more travel time, enjoy the beautiful scenery from all over the world, taste special food, and conduct car testing in combination with work. Third, stick to fitness and plan to check in 100 times in the gym to strengthen your body. Lei Jun admitted in the live broadcast that he traveled around in 2024, with a compact schedule, so he often only stayed for a short time, making it difficult to experience the local culture in depth. For example, at the New North Speedway in Germany, he stayed for only 8 hours. Therefore, in the new year, he hopes to be able to better balance work and life and travel

The micro-film "Memory Travel" created by No. 9 and brand spokesperson Yi Yang Qianxi won several authoritative media awards in 2024 and became a masterpiece of the year. This work has won high praise from the industry for its unique narrative style, exquisite production and sincere emotions. 2024 Awards and Honors: 2024 Gold Touch Global Business Innovation Award - Annual Film and Television Advertising 2024 China Advertising Marketing Award - Entertainment Marketing Group Silver Award 2024 Top Digital Innovation Marketing Award - Film and Television Production Gold Award 2024 Shanghai International Advertising Festival - Microfilm Silver Award 2024 The 11th China Innovation Communication Award - Integrated Marketing Silver Award WISE 2024 King of Business - Annual Case 31st China International Advertising Festival 2024 Digital Marketing Practical Big

Recently, the PConline2024 Zhizhen Technology Award was officially announced, and AGON Aidong QD-OLED e-sports display AG326UD won the "Technical Innovation of the Year" award. This honor not only represents the industry's high recognition of its technological advantages and market performance, but also fully reflects AGON's innovative capabilities and outstanding achievements in the field of e-sports display technology. 01. Looking at the future of technology, the authoritative value of the PConline Zhizhen Technology Award is the weather vane of the technology industry. The PConline Zhizhen Technology Award has successfully won wide industry recognition with its rigorous evaluation system and in-depth industry analysis. The award has always been committed to commending outstanding products and brands that promote the development of the technology industry, covering technology


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function