admin管理员组

文章数量:1122826

When I try to access the below URL in my WordPress website on the NGINX server it's showing a 400 Bad Request error. I want to show a custom page whenever this error message occurs. For example, when I try to access the below URL it's showing 400 Bad Request nginx error page. Here is the URL I am entering to generate the error.

/wp-content/plugins/..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fhosts

What will be the best solution for this?

When I try to access the below URL in my WordPress website on the NGINX server it's showing a 400 Bad Request error. I want to show a custom page whenever this error message occurs. For example, when I try to access the below URL it's showing 400 Bad Request nginx error page. Here is the URL I am entering to generate the error.

https://staging-vdt2zeq-h5nh2nj2vb2xg.au.platformsh.site/wp-content/plugins/..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2f..%2fetc%2fhosts

What will be the best solution for this?

Share Improve this question asked Jun 19, 2023 at 7:12 tek bhatttek bhatt 15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To display a custom error page for 400 errors on an Nginx server, you can try and use a custom error page. This could be an HTML page with the content you want to show to users when they hit a 400 error.

Once you have created the custom error page, you will need to edit your Nginx configuration file. This is usually located at /etc/nginx/nginx.conf or /etc/nginx/sites-available/default or a similar location, depending on your server setup.

You would then add an error_page directive inside the server block for your site, pointing to the location of your custom error page. It would look something like this:

server {
    listen 80 default_server;
    server_name example.com;
    
    # Rest of your configuration...

    error_page 400 /path/to/your/error400.html;
    location = /path/to/your/error400.html {
        internal;
    }
}

In the above configuration, replace /path/to/your/error400.html with the actual path to your custom error page. You might need to restart your Nginix service to make these changes work.

本文标签: How to display a custom page for 400 error message for WordPress website hosted on a NGINX server