Score:0

Nginx location directive not working

sy flag

My Nginx config file is:

server {
    listen 80;
    server_name localhost;
    location /a/ {
        return 404;
    }
    return 301;
}

When I run a request:

curl -v http://localhost/a/

I expect to see 404 code. But I receive 301 code. Why location /a/ {} directive is not working?

Score:3
sy flag

The return directive must be inside the location block, unless it is the only one in server block.

This configuration works as intended:

server {
    listen 80;
    server_name localhost;
    location /a/ {
        return 404;
    }
    location / {
        return 301;
    }
}
I sit in a Tesla and translated this thread with Ai:

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.