Nginx prohibits direct access via IP and redirects to a custom 500 page

Nginx prohibits direct access via IP and redirects to a custom 500 page

Directly to the configuration file

 server {              
 listen 80 default; # To prohibit direct access to the IP, you need to add default          
 server_name ~.*;                       
 error_page 404 400 402 401 /404.html; # Define the HTML file corresponding to the error status code location = /404.html {           
 # If you use a relative path, you should put the file in html/ under the nginx installation directory, for example: /usr/local/nginx/html/404.html
  root html;        
 }              
 error_page 500 /500.html;           
 location = /500.html {           
  root html;            
 }                        
 error_page 502 /502.html;           
 location = /502.html {           
  root html;            
 }             
 location / { # You must write the access IP here to jump to the custom 500.html           
  return 500;            
 }
 #return 500; # If written like this, it will jump to nginx's default 500 page}

This is the result of writing return 500;

This is the location

Additional knowledge: Solution to the problem that nginx still jumps to the welcome interface no matter how it is configured

Hello, fellow ape friends. When you use nginx for the first time, do you encounter the problem that no matter how you modify the nginx.conf file, it still jumps to the welcome interface? Then I searched Baidu and it was all in vain. You say you are not desperate? Are you angry? Don't panic, the savior is coming. . . . .

Causes of this problem: * Bro, you changed the wrong place. . . **

**After successfully installing nginx under Linux, people who use nginx for the first time will habitually find nginx.conf in the unzipped directory and then modify it. This is actually wrong and the modification will not have any effect.

The correct way is to use the whereis nginx command to find the nginx.conf file in the nginx installation directory and modify it**

The above operation of nginx prohibiting direct access through IP and jumping to a custom 500 page is all the content that the editor shares with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of the solution for NGINX to jump from https to http
  • How to redirect URL using nginx rewrite
  • How to redirect HTTP 301 to a domain name with www in Nginx server
  • How to force nginx to use https access (http jumps to https)
  • How to configure Nginx page redirection according to different browser languages
  • Detailed explanation of nginx to solve the problem of home page jump
  • Detailed explanation of nginx 301 redirect to domain name with www
  • Solution to nginx not jumping to the upstream address
  • How to redirect to https through nginx load balancing
  • Using Nginx's map command to redirect pages
  • Solve the problem of only redirecting to the home page when deploying thinkPHP 5 with nginx
  • Example code for using Nginx to implement 301 redirect to https root domain name
  • Detailed explanation of Nginx rewrite jump application scenarios
  • Detailed explanation of how to enable HSTS in nginx to force the browser to redirect to HTTPS access
  • Implementation of rewrite jump in nginx
  • Detailed explanation of location matching and rewrite redirection in Nginx
  • Nginx hidden redirect (browser URL remains unchanged after redirection)

<<:  Ajax responseText parses json data case study

>>:  Detailed steps for installing MySQL using cluster rpm

Recommend

Docker container time zone error issue

Table of contents background question Problem ana...

A brief summary of vue keep-alive

1. Function Mainly used to preserve component sta...

mysql 5.7.11 winx64.zip installation and configuration method graphic tutorial

Install and configure the MySql database system. ...

Using jQuery to implement the carousel effect

What I bring to you today is to use jQuery to imp...

CSS float property diagram float property details

Using the CSS float property correctly can become...

Docker-compose installation yml file configuration method

Table of contents 1. Offline installation 2. Onli...

Ubuntu 20.04 how to modify the IP address example

illustrate: Today, when continuing the last offic...

Solve the problem of inconsistent MySQL storage time

After obtaining the system time using Java and st...

Zabbix configuration DingTalk alarm function implementation code

need Configuring DingTalk alarms in Zabbix is ​​s...

Why MySQL does not recommend using subqueries and joins

To do a paginated query: 1. For MySQL, it is not ...

Nginx tp3.2.3 404 problem solution

Recently I changed Apache to nginx. When I moved ...

Causes and solutions for cross-domain issues in Ajax requests

Table of contents 1. How is cross-domain formed? ...