Welcome! Log In Create A New Profile

Advanced

custom error pages for retun directive

kay
August 26, 2014 04:48AM
It is not possible to set custom error page. For example /usr/share/nginx/404.html contains "test":

server {
error_page 404 /404.html;

if ($request_method = "GET")
return 404;
}

location / {
proxy_pass http://localhost:8080;
}

location /404.html {
/usr/share/nginx/404.html;
}
}


curl -v 127.0.0.1
* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 127.0.0.1
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Server: nginx
< Date: Tue, 26 Aug 2014 08:45:26 GMT
< Content-Type: text/html
< Content-Length: 162
< Connection: keep-alive
< Keep-Alive: timeout=20
<
<html>
<head><title>404 Not Found</title></head>
<body bgcolor="white">
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0

But if I'll make rewrite rule:

server {
error_page 404 /404.html;

if ($request_method = "GET")
rewrite ^ /404.html last;
}

location / {
proxy_pass http://localhost:8080;
}

location /404.html {
/usr/share/nginx/404.html;
}
}

I'll get:

curl -v 127.0.0.1
* About to connect() to 127.0.0.1 port 80 (#0)
* Trying 127.0.0.1... connected
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 127.0.0.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx
< Date: Tue, 26 Aug 2014 08:46:25 GMT
< Content-Type: text/html
< Content-Length: 5
< Last-Modified: Tue, 26 Aug 2014 08:42:47 GMT
< Connection: keep-alive
< Keep-Alive: timeout=20
< ETag: "53fc4887-5"
< Accept-Ranges: bytes
<
test
* Connection #0 to host 127.0.0.1 left intact
* Closing connection #0

But I'll get 200 OK.

Is it possible to get cutsom 404 error page with 404 error code using "return 404" directive?
Subject Author Posted

custom error pages for retun directive

kay August 26, 2014 04:48AM

Re: custom error pages for retun directive

Maxim Dounin August 26, 2014 08:00AM

Re: custom error pages for retun directive

kay August 26, 2014 08:41AM

Re: custom error pages for retun directive

Maxim Dounin August 26, 2014 09:54AM

Re: custom error pages for retun directive

kay August 26, 2014 11:01PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 63
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready