How to get the correct HTTP status?

6

I tried to get the error "status" like this:

error_page 403 /error.php;
error_page 404 /error.php;

But $_SERVER['REDIRECT_STATUS'] return 200 , already in Apache it returns 404 (the expected result).

How can I define the variables $_SERVER[REDIRECT_STATUS] , $_SERVER[REDIRECT_REQUEST_METHOD] and $_SERVER[REDIRECT_URL] using Nginix?

    
asked by anonymous 04.05.2015 / 04:06

1 answer

2

After a brief search, I found this ikiwiki , there are some improvements that can be made but the idea is that location fault solves the problem, over time I will either improve the code or add a new example.

Basic example:

# Configura um local "falso" para
error_page 404 @fakeroute404;

# Acessa o local falso
location @fakeroute404 {
    ...# Outros dados

    include /etc/nginx/fastcgi_params; #inclui os parametros fastcgi

    fastcgi_param REQUEST_METHOD "GET"; # Configura o metodo
    fastcgi_param REDIRECT_STATUS 404;  # Configura o estado
    fastcgi_param REDIRECT_URL $uri;    # Configura a URL
}
    
13.06.2015 / 20:37