Redirect when site is unavailable.
August 30, 2016 12:20PM
I'm wondering if its possbile to configure Nginx to detect when a site is down, and redirect or serve an alternate page when said site is down.
For example, I have a Sharepoint site that we use as our intranet site. I would like to be able to present or redirect to a basic alternate webpage with some hyperlinks that end users commonly use.
Re: Redirect when site is unavailable.
September 06, 2016 07:16PM
I was able to get Nginx configured as a proxy to our Sharepoint WebApp server with the following config:

user nginx;
worker_processes 1;

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


events {
worker_connections 1024;
}


stream {
server {
listen *:80;
proxy_pass backend;

}

upstream backend {
server sharepoint:80;
}



}

That works great, but it still doesnt solve my problem.

I found an example config that appears to watch for a maintenance.html file and if detected returns the maintenance.html with a rewrite command. I figured I could use this in my config, and have my Solarwinds monitor run a script to copy the maintenance.html file to the designated path when it detects the site is down.

This is the example config I found, that I tried to integrate into my current config:

server {
listen 80;
server_name mysite.com;
root /var/www/mysite.com/;

location / {
if (-f $document_root/maintenance.html) {
return 503;
}
... # the rest of your config goes here
}

error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
}

Now I am a total newbie with Nginx, so go easy on me if this is painfully obvious, but this is what I came up with when I attempted to integrate it into my current config:

user nginx;
worker_processes 1;

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

events {
worker_connections 1024;
}


stream {
server {
listen *:80;
root /etc/nginx/;
location / {
if (-f $document_root/maintenance.html) {
return 503;
}
}
error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}
proxy_pass backend;
}

upstream backend {
server connect:80;
}

}

I keep getting nginx: [emerg] "root" directive is not allowed here in /etc/nginx/nginx.conf :16 when trying to load the config. I've tried moving the root /etc/nginx/; directive around in the config, but I keep getting the same error, just with a different line identifier in the error code. Any help you can offer to get this working is greatly appreciated.
Re: Redirect when site is unavailable.
September 07, 2016 02:12AM
gdalton240 Wrote:
-------------------------------------------------------
> stream {
> server {
> listen *:80;
> root /etc/nginx/;

root has no meaning when using stream {} since 'stream' just a tcp proxy.

---
nginx for Windows http://nginx-win.ecsds.eu/
Re: Redirect when site is unavailable.
September 07, 2016 07:42PM
Ok thanks. Back to the drawing board.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 175
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready