Welcome! Log In Create A New Profile

Advanced

mod_proxy+mod_cache - no upstream & set error_page?

Scott Smith
April 12, 2010 02:50PM
Hi,

I'm using Nginx with mod_proxy+mod_cache to proxy and cache specific pages.

When the upstream ($host) is down, and the page is not cached, Nginx
returns a generic 502 page. Is it possible to use error_page?

I've tried putting error_page 502 directive in multiple places to no avail.

Here is my full config:

user daemon;
worker_processes 5;
worker_rlimit_nofile 20480;

error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

events {
worker_connections 4096;
# multi_accept on;
use epoll;
}

http {
include /etc/nginx/mime.types;

access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_disable msie6;
gzip_proxied any;

proxy_cache_path /path/to/cache levels=1:1:2
keys_zone=maint_cache:512m inactive=15d max_size=30g;
proxy_hide_header Expires;
proxy_hide_header Cache-Control;

server {
listen 80;
server_name foo.bar.com;

location /nginx_status {
stub_status on;
access_log off;
allow 10.0.0.0/8;
deny all;
}

root /path/to/htdocs;

log_format cache_log '$time_local '
'$upstream_cache_status '
'Cache-Control: $upstream_http_cache_control '
'Expires: $upstream_http_expires '
'"$request" ($status) '
'"$http_user_agent" ';

access_log /var/log/nginx/proxy.access.log;
access_log /var/log/nginx/proxy.cache.log cache_log;

proxy_cache mycache;
proxy_set_header Host $http_host;
proxy_cache_use_stale error timeout updating http_500 http_502
http_503 http_504 http_404;

error_page 404 /default/index.html;

if ($host ~* ^([a-z0-9\-]+\.([a-z]+))$) {
set $host_with_www www.$1;
}

if ($host !~* ^([a-z0-9\-]+\.([a-z]+))$) {
set $host_with_www $host;
}

location ~ /purge(/.*) {
proxy_cache_purge mycache "$host_with_www$1";
allow 10.0.0.0/8;
deny all;
}

# The initial request MUST respond with HTTP 503.
location ~ ^/$ {
error_page 503 /503index;
return 503;
}

location /503index {
proxy_pass http://$host_with_www/path/to/index.php;
proxy_cache_key "$host_with_www/index.php";
}

# If the CSS request isn't HTTP 200 some browsers don't render
location /path/to/styles.css {
proxy_pass http://$host_with_www/path/to/styles.css;
proxy_cache_key "$host_with_www/styles.css";
}

location ~ /.*$ {
error_page 503 /503index;
return 503;
}
}

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

mod_proxy+mod_cache - no upstream & set error_page?

Scott Smith April 12, 2010 02:50PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 57
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