D
D
Denis2011-03-25 17:15:19
Nginx
Denis, 2011-03-25 17:15:19

nginx redirect

Hello.
I have already asked a similar question before. Now there are clarifications to which at first I did not attach due importance.

There is a php script. There is nginx. It is necessary to make it so that nginx would return a certain page in case of an error in the script or if the script fell off by timeout. I tried to make a bunch of nginx + apache (apache - backend) - then nginx does not respond to errors in the script. Rather, a 500 error is returned (it is returned by the script itself), but the page is not replaced by what I need.
I tried to fasten php to nginx according to this article. The result is similar.

The nginx config contains the following lines: The php script itself looks like this:

error_page 404 500 /500.html;
location = /500.html {
root /var/www/nginx-default;
}



<?
sleep(5);
header("HTTP/1.1 500 Internal Server Error");
?>


I tried to set up a redirect in apache, but I couldn't. In .htacces, I wrote this: Now I directly contact apache (it is on port 8080), requesting a non-existent page and getting a standard 404 error page. At the same time, for example, nginx catches a 404 error and returns the desired page. Logs are clean. All errors in the logs are related to the request of a non-existent page. What am I doing wrong? UPD Can you tell me what I'm doing wrong in the case of setting up a redirect in Apache? I also googled proxy_intercept_errors is that it?

ErrorDocument 404 192.168.0.252/500.html
ErrorDocument 500 192.168.0.252/500.html









Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wott, 2011-03-25
@uscr

If you want to replace the Apache response with your page, then you need to specify proxy_intercept_errors
on in the location where the proxy is registered;
here is a piece of production If you want to give everything as it is, then you don’t need it: a piece of development config
error_page 404 500 501 502 504 /error.html;
location = /error.html {
internal;
}
error_page 503 /maintenance.html;
location /maintenance.html {
#pass
}
location / {
if (-f $document_root/maintenance.html) {
return 503;
}
proxy_intercept_errors on;
proxy_cache one;
proxy_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
proxy_cache_valid 200 301 302 304 1h;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass 127.0.0.1:8080;
}

error_page 503 /maintenance.html;
location /maintenance.html {
#pass
}
location / {
if (-f $document_root/maintenance.html) {
return 503;
}
proxy_cache one;
proxy_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri";
proxy_cache_valid 200 301 302 304 1h;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass 127.0.0.1:8080;
}

E
Evgeny Bezymyannikov, 2011-03-25
@psman

habrahabr.ru/qa/6090/

V
Vlad Frolov, 2011-03-25
@frol

recursive_error_pages on;
Details here: sysoev.ru/nginx/docs/http/ngx_http_core_module.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question