Nginx server redirect to Error Server not working
January 27, 2020 01:05PM
Hi Team and Techies,

I need your help.
I have been searching for a solution to this problem. Here is my setup.
Server A:
Nginx Server Latest version: 01-2020 version. Serves as Reverse proxy for all sites served by Server B.
Apache Server ( Serves two purposes): 1. Serve sites, 2. Serve as Error server if "Server B being down"
Server B:
Apache Server: Main Site Server.
When Server B is down, Server A should serve as an "Error page" with same domain name. For example:
if Server B serves:, and if it is down, then Server A will serve the error page as below: if the error is 502 error, it should serve from Server A.
error.html can be manipulated using JavaScript to display the appropriate error.
Is this possible using load balancer ? or regular setup. Here is the configuration file:

Server A: (Nginx Server) /etc/nginx/conf.d/

server {
listen 80;
if ($host = ) {
return 301$request_uri;
# return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = ) {
return 301$request_uri;
# return 301 https://$host$request_uri;
} # managed by Certbot


server {
listen 443 ssl;

root /var/www/;

ssl_certificate /etc/letsencrypt/live/;
ssl_certificate_key /etc/letsencrypt/live/;

ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

location / {
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_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
proxy_send_timeout 300;
proxy_read_timeout 300;
send_timeout 300;
proxy_intercept_errors on;
error_page 404 500 502 503 504 = @fallback;

proxy_read_timeout 90;
#rewrite redirect;

index index.php index.html index.htm index.nginx-debian.html;

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;

location ~ /\.ht {
deny all;

location @fallback {
root /var/www/;
rewrite ^/(.*);
#rewrite ^/(.*) permanent;

Sorry, only registered users may post in this forum.

Click here to login

Online Users

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