doupu9251 2016-11-10 00:53
浏览 45

将NGINX设置为故障转移Web服务器

I have 2 versions of a web application that I want to server content from. I would like to setup nginx to try the first one, and if it gets a 404 then try the second one. (I mostly have this part working.) But I also want nginx to remember for a certain period of time that a requested URI was not found with web app 1 and try web app 2 first.

We are creating a new version of our application that has an all new code base. We want the webserver to try that one first, it is setup to 404 fast if the route passed isnt implemented yet so I then need the webserver to go back to the old version. That server will handle the error pages as well if it really is a 404.

Here is what i have so far:

server {
    listen 80;
    server_name domain.com

    location @webapp {
        include proxy.conf;
        proxy_intercept_errors off;
        proxy_pass http://webapp;
        error_page 403 404 = @webapp2;
    }

    location @webapp2 {
        include proxy.conf;
        proxy_intercept_errors off;
        proxy_pass http://webapp2;
        error_page 403 404 = @error;
    }

    location / {
        proxy_pass http://webapp;
        include proxy.conf;
        error_page 403 404 = @webapp2;
    }

Then I have a file for each of the web apps thats basically:

upstream webapp {
    server 127.0.0.1:81;
}

server {
    listen 81;
    server_name domain.com;
    root /var/www/domain.com;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    ...
}

And the other one uses port 82, this works perfectly for fail over. But i cant get it to remember that web app 2 served a URI and to go straight their for all requests for the next X time.

Any help or advise on better ways to solve this will be greatly appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 mmocr的训练错误,结果全为0
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀