Score:0

How can I test the NGINX 5xx error configuration (generate a 5xx error)?

in flag

I am setting up a new web server using NGINX and I would like to test the error page configuration. This is easy enough to do for a 404 but I want to test the 5xx configuration and so need to at least be able to generate one of the 500-series errors from a request.

Can anyone give me a clue please as to how to do that?

Ivan Shatsky avatar
gr flag
Use `return 500;` or any other code, it will trigger your custom error page :)
Score:1
us flag

I'm pretty sure you could use try_files with a nonexistent file. The command has a fallback option that can throw an error code of your choice: try_files file ... =code; guide here, docs here

server {  
    listen 80;
    root /www/data;

    location /throw_500 {
        try_files $uri $uri/ =503;
    }
}

In this case, just access http://server/throw_500 (empty $uri passed) and the error will be thrown.

in flag
Many that @rgon, what you've given does work and I've given it an upvote. However, there is also a simpler answer based on Ivan's comment.
Score:0
in flag

The simplest answer is to use a non-existant location containing a return 500; statement.

server {  
    listen 80;

    location /throw503 {
        return 503;
    }
}

Many thanks to Ivan and rgon. I couldn't see the wood for the trees

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.