-
-
Save justinriggio/6350687 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream my_upstream { #this line starts the list of real resources that exist behind the nginx server | |
server 127.0.0.1:1337; | |
server 127.0.0.1:1338; #these servers are used in the order they are defined, in round robin fashion. there's more ways of load balancing in the docs | |
server 127.0.0.1:1339 backup; #amazingness no.1, the keyword "backup" means that this server should only be used when the rest are non-responsive | |
keepalive 64; | |
} | |
server { | |
listen 80; | |
location /resource.html { #in my example the server only responds to requests for the file /request.html | |
proxy_redirect off; | |
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_set_header Host $http_host; | |
proxy_set_header X-NginX-Proxy true; | |
proxy_set_header Connection ""; | |
proxy_http_version 1.1; | |
proxy_pass http://my_upstream; #this sets the name of the server list that will actually process the request | |
proxy_intercept_errors on; #amazingness no.2 if all of the proxied servers are down, this will return a 50x error (bad gateway) with this line we tell nginx to intercept this error instead of giving it back to the user | |
error_page 502 503 504 =200 http://failoverhost.com/resource.html #in combination with the line above, if a 50x error exists nginx will redirect to the example host that can server the static content | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment