Top Poster
#1 ramon fincken 400
#2 Site admin 3
#3 Ber|Art 2
#4 braddmark 1
#5 accentmedia 1
#6 Xarzu 1
#7 pEcosespedex 1
#8 khadish 1
#9 moxxx 1
#10 nistelrock 1
[nginx] multiple fallback locations (try each one)



Rating : 3 / 5

 
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> Bash, perl, python and CLI linux
Beta
Want to be notified by email when this topic gets a reply?  
View previous topic :: View next topic  
Author Message
ramon fincken
Site's programmer

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 400
Location: A'dam/Diemen, The Netherlands

PostPosted: Wed Nov 04, 2015 9:14 am    Post subject: [nginx] multiple fallback locations (try each one) Reply with quote

Update 1: see reply below for a much better version

This proxy setup will fetch all content from @static_svr1, and if not found (proxy_intercept_errors) it will get it from the original server @static_svr2

Feel free to chain this to have some more.

Code:
server {
        listen 80; #Port that my custom app was assigned
        server_name domain.ext www.domain.ext;
        location / {
                try_files $uri @static_svr1;
        }
        location @static_svr1{
                proxy_pass http://fallbackurl.ext;
                proxy_intercept_errors on;
                error_page 404 = @static_svr2;
        }

        location @static_svr2{
                proxy_pass http://originalurl.ext;
        }
}


A word of caution:
fallbackurl.ext != domain.ext
originalurl.ext != domain.ext

so use domain pointers on your target servers for that.


Main source:
http://linuxplayer.org/2013/06/nginx-tr...-or-server


Last edited by ramon fincken on Sat Nov 21, 2015 5:21 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Google adsense
Advertisement





PostPosted: Wed Nov 04, 2015 9:14 am    Post subject: [nginx] multiple fallback locations (try each one)

Advertisement
Back to top
GravityForms
Advertisement





PostPosted: Wed Nov 04, 2015 9:14 am    Post subject: [nginx] multiple fallback locations (try each one)

Advertisement
Gravity Forms Plugin for WordPress
Back to top
ramon fincken
Site's programmer

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 400
Location: A'dam/Diemen, The Netherlands

PostPosted: Wed Nov 18, 2015 2:07 pm    Post subject: Re: [nginx] multiple fallback locations (try each one) Reply with quote

Here we go for multiple remote servers having multiple hostnames (so 1 sites under different hostnames on each backend server)

Code:

server {
        listen                  8001 default_server;
        server_name             user_local;
        location / {
               root /home/user/www;
        }
}

server {
        listen                  8002 default_server;
        server_name             web1.example.com;
        location / {
                proxy_pass                      http://web1.local:80;
                proxy_set_header        Host    web1.local:80;
        }
}

server {
        listen                  8003 default_server;
        server_name             web2.example.com;
        location / {
                proxy_pass                      http://web2.local:80;
                proxy_set_header        Host    web2.local:80;
        }
}

server {
        listen                  8004 default_server;
        server_name             web3.example.com;
        location / {
                proxy_pass                      http://web3.local:80;
                proxy_set_header        Host    web3.local:80;
        }
}

upstream main {
        server 127.0.0.1:8001;
        server 127.0.0.1:8002;
        server 127.0.0.1:8003;
        server 127.0.0.1:8004;
}

server {
        listen                  80;
        server_name             example.com;
        location / {
                proxy_pass      http://main;
                proxy_next_upstream     error timeout invalid_header http_500 http_502 http_503 http_404;
        }
}



Sources:
http://serverfault.com/questions/598202...seproxying
http://stackoverflow.com/questions/1324...e-backends
http://stackoverflow.com/questions/1286...oesnt-work
Back to top
View user's profile Send private message Visit poster's website
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> Bash, perl, python and CLI linux All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
General forums
The world of freelance
Programming
Other projects
Poll
I love gifts

Yes goodies and presents! [3]
No but I love polls ! [1]

Related google ads